Install
$ agentstack add skill-flydev-fr-mormot2-superpowers-mormot2-core ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
mormot2-core
Foundational mORMot 2 layer: string and byte types, conditional defines, unit dependency order, JSON, RTTI registration, dynamic documents, and lightweight thread-safety primitives. This skill is authoritative for the mormot.core.* namespace and the mormot.defines.inc / mormot.uses.inc include files. Sibling skills (orm, rest-soa, db, net, auth-security) build on top of this layer and assume its conventions.
When to use
- Choosing between
string,RawUtf8,RawByteString,WinAnsiString,SynUnicode, orUnicodeStringfor a field, parameter, or return value. - Setting or unsetting a toggle in
mormot.defines.inc(PUREMORMOT2, FPCX64MM, FPCMMBOOST, FPCMM_SERVER, NEWRTTINOTUSED, NOPATCHVMT, NOPATCHRTL). - Adding a
mormot.core.*(or higher) unit to ausesclause and unsure of dependency order. - Registering custom RTTI for a record or class so it serializes/deserializes through mORMot JSON.
- Working with
TDocVariant,IDocList, orIDocDictfor schema-less JSON-shaped data. - Using
TSynLockerorTSynLockedto protect shared state on a hot path without paying the cost ofTCriticalSection.
When NOT to use
- Defining
TOrmclasses,TOrmModel, or wiring an ORM virtual table. Use mormot2-orm. - Building REST endpoints, interface-based services, or SOA contracts. Use mormot2-rest-soa.
- Writing raw SQL, configuring DB providers (PostgreSQL, MSSQL, MongoDB, ZEOS, FireDAC). Use mormot2-db.
- HTTP server/client work, WebSockets, TLS, or network buffer tuning. Use mormot2-net.
- JWT, signing, AES, OpenSSL bindings, or auth flows. Use mormot2-auth-security.
Core idioms
1. RawUtf8 boundary conversions
Convert at the edge ONCE. Internally everything is RawUtf8. Touch string only at UI/RTL boundaries.
uses
mormot.core.base,
mormot.core.unicode;
var
utf8: RawUtf8;
display: string;
begin
utf8 := StringToUtf8(Edit1.Text); // VCL/UI -> internal (once, at the edge)
// ... business logic uses utf8 only ...
Edit1.Text := Utf8ToString(utf8); // internal -> VCL/UI (once, on the way out)
end;
2. TSynLocker
Stack-allocated, requires explicit Init and Done. Cheaper and more cache-friendly than TCriticalSection for short critical sections.
uses
mormot.core.os;
var
Lock: TSynLocker;
Counter: Integer;
begin
Lock.Init;
try
Lock.Lock;
try
Inc(Counter);
finally
Lock.UnLock;
end;
finally
Lock.Done;
end;
end;
3. TDocVariant
Late-binding JSON-shaped variants. _Json builds from text, _Obj / _Arr build from in-memory arrays.
uses
mormot.core.variants;
var
doc: variant;
begin
doc := _Json('{"user":{"id":42,"name":"Ada"},"tags":["admin","beta"]}');
WriteLn(doc.user.name); // dotted path via late binding
doc.user.email := 'ada@example.com'; // add new property
TDocVariantData(doc).U['user.id'] := '42'; // typed path access via _Safe / typed cast
end;
4. Custom record RTTI
Use the text DSL once at startup so every RecordSaveJson / RecordLoadJson / TJsonWriter.AddRecordJson knows the field shape.
uses
mormot.core.rtti;
type
TPriceRow = packed record
Symbol: RawUtf8;
Price: currency;
Ts: TDateTime;
end;
initialization
Rtti.RegisterFromText(TypeInfo(TPriceRow),
'Symbol:RawUtf8 Price:currency Ts:TDateTime');
end.
5. Layered uses (dependency order matters)
Lower layers never uses higher ones. Always include mormot.core.base first; pull mormot.core.rtti before mormot.core.json if you do custom serialization. For the memory manager, include mormot.uses.inc once in your .dpr.
program myserver;
{$I mormot.defines.inc}
uses
{$I mormot.uses.inc} // FPC_X64MM / FPCMM_BOOST etc. live here
mormot.core.base, // RawUtf8, PtrInt, primitive types
mormot.core.os, // TSynLocker, GetTickCount64
mormot.core.unicode, // StringToUtf8 / Utf8ToString
mormot.core.text, // FormatUtf8, CSV
mormot.core.rtti, // Rtti.RegisterFromText
mormot.core.variants,// TDocVariant
mormot.core.json, // TJsonWriter, GetJsonField
// higher layers (orm/rest/net) come after.
SysUtils;
Common pitfalls
- Mixing
stringandRawUtf8in business logic. Each implicit cast is a UTF-16 UTF-8 round trip. PickRawUtf8everywhere except UI/RTL. - Importing
mormot.core.jsonbeforemormot.core.rtti. Custom RTTI registration must already be visible when JSON serializers initialize. Wrong order = "type not registered" at runtime. - Forgetting
{$I ..\mormot.defines.inc}at the top of a unit. Without it, conditionals likeFPC_X64MMandNEWRTTINOTUSEDare not seen and the unit compiles with the wrong feature set. - Using
TSynLockerlikeTCriticalSection. It is a stack-allocated record. You MUST callLock.Initbefore first use andLock.Donebefore it goes out of scope, or you leak the underlying OS primitive. - Reusing a
TJsonWriteracross threads without locking.TJsonWriteris single-threaded by design. Either keep one per thread or guard it with aTSynLocker. - Storing binary blobs in
RawUtf8. UseRawByteStringfor binary;RawUtf8carries a UTF-8 codepage hint that some helpers will honor.
See also
$MORMOT2_DOC_PATH/mORMot2-SAD-Chapter-04.md- Core Units$MORMOT2_DOC_PATH/mORMot2-SAD-Chapter-03.md- Unit Structurereferences/raw-utf8-cheatsheet.mdreferences/conditional-defines.mdreferences/unit-hierarchy.mdreferences/json-rtti-idioms.mdmormot2-ormfor TOrm-specific RTTI
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: flydev-fr
- Source: flydev-fr/mormot2-superpowers
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.