@theokit/orm 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,12 @@
1
1
  import { Table } from 'drizzle-orm';
2
2
 
3
+ /**
4
+ * A JSON Schema draft-07 object describing one table.
5
+ *
6
+ * This is the contract a non-TypeScript consumer reads. `additionalProperties` is fixed to `false`
7
+ * so a generator in another language produces a closed model rather than one that silently accepts
8
+ * columns this table does not have.
9
+ */
3
10
  type JsonSchema7 = {
4
11
  $schema?: string;
5
12
  title?: string;
@@ -8,6 +15,13 @@ type JsonSchema7 = {
8
15
  required: string[];
9
16
  additionalProperties: false;
10
17
  };
18
+ /**
19
+ * One column, as JSON Schema draft-07 sees it.
20
+ *
21
+ * `x-check` is the one field outside the standard: it carries the SQL check constraint verbatim,
22
+ * because draft-07 has no vocabulary for it and dropping it would let a generated model accept
23
+ * values the database will reject.
24
+ */
11
25
  type JsonSchema7Property = {
12
26
  type?: "string" | "integer" | "number" | "boolean" | "object" | "array" | "null";
13
27
  format?: string;
@@ -19,7 +33,26 @@ type JsonSchema7Property = {
19
33
  "x-check"?: string;
20
34
  description?: string;
21
35
  };
36
+ /**
37
+ * Emit the JSON Schema draft-07 description of one Drizzle table.
38
+ *
39
+ * A column is `required` when it is `NOT NULL` and has no default — the two together are what
40
+ * decide whether a caller must supply a value, and treating `NOT NULL` alone as required would
41
+ * demand values the database would have filled in.
42
+ *
43
+ * @throws {OrmSchemaExportError} when a column's type has no mapping. Emitting a partial schema
44
+ * would be worse than failing: a consumer in another language would generate a model missing a
45
+ * field and discover it at the first insert.
46
+ */
22
47
  declare function exportSchema(table: Table): JsonSchema7;
48
+ /**
49
+ * Emit one schema per table, keyed by the table's name in the database rather than by the key it
50
+ * has in the Drizzle schema object — the two differ whenever a table is declared as
51
+ * `users: sqliteTable("app_users", ...)`, and a consumer generating models needs the name the
52
+ * database answers to.
53
+ *
54
+ * @throws {OrmSchemaExportError} from the first table that has an unmappable column.
55
+ */
23
56
  declare function exportSchemas(schema: Record<string, Table>): Record<string, JsonSchema7>;
24
57
 
25
58
  export { type JsonSchema7, type JsonSchema7Property, exportSchema, exportSchemas };
@@ -1,5 +1,12 @@
1
1
  import { Table } from 'drizzle-orm';
2
2
 
3
+ /**
4
+ * A JSON Schema draft-07 object describing one table.
5
+ *
6
+ * This is the contract a non-TypeScript consumer reads. `additionalProperties` is fixed to `false`
7
+ * so a generator in another language produces a closed model rather than one that silently accepts
8
+ * columns this table does not have.
9
+ */
3
10
  type JsonSchema7 = {
4
11
  $schema?: string;
5
12
  title?: string;
@@ -8,6 +15,13 @@ type JsonSchema7 = {
8
15
  required: string[];
9
16
  additionalProperties: false;
10
17
  };
18
+ /**
19
+ * One column, as JSON Schema draft-07 sees it.
20
+ *
21
+ * `x-check` is the one field outside the standard: it carries the SQL check constraint verbatim,
22
+ * because draft-07 has no vocabulary for it and dropping it would let a generated model accept
23
+ * values the database will reject.
24
+ */
11
25
  type JsonSchema7Property = {
12
26
  type?: "string" | "integer" | "number" | "boolean" | "object" | "array" | "null";
13
27
  format?: string;
@@ -19,7 +33,26 @@ type JsonSchema7Property = {
19
33
  "x-check"?: string;
20
34
  description?: string;
21
35
  };
36
+ /**
37
+ * Emit the JSON Schema draft-07 description of one Drizzle table.
38
+ *
39
+ * A column is `required` when it is `NOT NULL` and has no default — the two together are what
40
+ * decide whether a caller must supply a value, and treating `NOT NULL` alone as required would
41
+ * demand values the database would have filled in.
42
+ *
43
+ * @throws {OrmSchemaExportError} when a column's type has no mapping. Emitting a partial schema
44
+ * would be worse than failing: a consumer in another language would generate a model missing a
45
+ * field and discover it at the first insert.
46
+ */
22
47
  declare function exportSchema(table: Table): JsonSchema7;
48
+ /**
49
+ * Emit one schema per table, keyed by the table's name in the database rather than by the key it
50
+ * has in the Drizzle schema object — the two differ whenever a table is declared as
51
+ * `users: sqliteTable("app_users", ...)`, and a consumer generating models needs the name the
52
+ * database answers to.
53
+ *
54
+ * @throws {OrmSchemaExportError} from the first table that has an unmappable column.
55
+ */
23
56
  declare function exportSchemas(schema: Record<string, Table>): Record<string, JsonSchema7>;
24
57
 
25
58
  export { type JsonSchema7, type JsonSchema7Property, exportSchema, exportSchemas };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/schema-export.ts"],"names":["OrmError","Error","name","OrmSchemaExportError","tableNameOf","table","sym","Symbol","for","inner","_","lower","s","toLowerCase","isInteger","dataType","columnType","test","matchEnum","meta","Array","isArray","enumValues","length","type","enum","matchUuid","_m","_dt","ct","format","matchNumeric","out","scale","multipleOf","matchBigint","matchDate","dt","matchBlob","contentEncoding","matchBoolean","matchJson","matchInteger","matchFloat","matchString","maxLength","COLUMN_MATCHERS","mapColumnToJsonSchema","colName","col","tableName","matcher","result","exportSchema","columns","getTableColumns","properties","required","Object","entries","prop","hasDefault","default","undefined","notNull","push","$schema","title","additionalProperties","exportSchemas","schema"],"mappings":";;;;;;AAAO,IAAMA,QAAAA,GAAN,cAAuBC,KAAAA,CAAAA;EAA9B;;;EACoBC,IAAAA,GAAe,UAAA;AACnC,CAAA;AAUO,IAAMC,oBAAAA,GAAN,cAAmCH,QAAAA,CAAAA;EAZ1C;;;EAaoBE,IAAAA,GAAO,sBAAA;AAC3B,CAAA;;;AC2BA,SAASE,YAAYC,KAAAA,EAAc;AACjC,EAAA,IAAIA,KAAAA,KAAU,IAAA,IAAQ,OAAOA,KAAAA,KAAU,UAAU,OAAO,WAAA;AACxD,EAAA,MAAMC,GAAAA,GAAOD,KAAAA,iBAAkCE,MAAAA,CAAOC,GAAAA,CAAI,cAAA,CAAA,CAAA;AAC1D,EAAA,IAAI,OAAOF,GAAAA,KAAQ,QAAA,EAAU,OAAOA,GAAAA;AACpC,EAAA,MAAMG,QAASJ,KAAAA,CAAoCK,CAAAA;AACnD,EAAA,OAAOD,OAAOP,IAAAA,IAAQ,WAAA;AACxB;AANSE,MAAAA,CAAAA,WAAAA,EAAAA,aAAAA,CAA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CAAK0C,eAAe,IAAA,EAAM;AAC5B,MAAA,IAAI1C,IAAAA,CAAK2C,YAAYC,MAAAA,EAAW;AAC9BH,QAAAA,IAAAA,CAAKE,UAAU3C,IAAAA,CAAK2C,OAAAA;AACtB,MAAA;AACF,IAAA;AAEA,IAAA,IAAI3C,IAAAA,CAAK6C,OAAAA,KAAY,IAAA,IAAQ7C,IAAAA,CAAK0C,eAAe,IAAA,EAAM;AACrDJ,MAAAA,QAAAA,CAASQ,KAAKjB,OAAAA,CAAAA;AAChB,IAAA;AAEAQ,IAAAA,UAAAA,CAAWR,OAAAA,CAAAA,GAAWY,IAAAA;AACxB,EAAA;AAEA,EAAA,OAAO;IACLM,OAAAA,EAAS,yCAAA;IACTC,KAAAA,EAAOjB,SAAAA;IACP1B,IAAAA,EAAM,QAAA;AACNgC,IAAAA,UAAAA;AACAC,IAAAA,QAAAA;IACAW,oBAAAA,EAAsB;AACxB,GAAA;AACF;AAhCgBf,MAAAA,CAAAA,YAAAA,EAAAA,cAAAA,CAAAA;AAkCT,SAASgB,cAAcC,MAAAA,EAA6B;AACzD,EAAA,MAAMtC,MAAmC,EAAC;AAC1C,EAAA,KAAA,MAAW,GAAG3B,KAAAA,KAAUqD,MAAAA,CAAOC,OAAAA,CAAQW,MAAAA,CAAAA,EAAS;AAC9C,IAAA,MAAMpE,IAAAA,GAAOE,YAAYC,KAAAA,CAAAA;AACzB2B,IAAAA,GAAAA,CAAI9B,IAAAA,CAAAA,GAAQmD,YAAAA,CAAahD,KAAAA,CAAAA;AAC3B,EAAA;AACA,EAAA,OAAO2B,GAAAA;AACT;AAPgBqC,MAAAA,CAAAA,aAAAA,EAAAA,eAAAA,CAAAA","file":"schema-export.js","sourcesContent":["export class OrmError extends Error {\n override readonly name: string = \"OrmError\";\n}\n\nexport class OrmConfigurationError extends OrmError {\n override readonly name = \"OrmConfigurationError\";\n}\n\nexport class OrmValidationError extends OrmError {\n override readonly name = \"OrmValidationError\";\n}\n\nexport class OrmSchemaExportError extends OrmError {\n override readonly name = \"OrmSchemaExportError\";\n}\n","import type { Column, Table } from \"drizzle-orm\";\nimport { getTableColumns } from \"drizzle-orm\";\nimport { OrmSchemaExportError } from \"./errors.js\";\n\nexport type JsonSchema7 = {\n $schema?: string;\n title?: string;\n type: \"object\";\n properties: Record<string, JsonSchema7Property>;\n required: string[];\n additionalProperties: false;\n};\n\nexport type JsonSchema7Property = {\n type?: \"string\" | \"integer\" | \"number\" | \"boolean\" | \"object\" | \"array\" | \"null\";\n format?: string;\n maxLength?: number;\n multipleOf?: number;\n default?: unknown;\n enum?: ReadonlyArray<string | number>;\n contentEncoding?: string;\n \"x-check\"?: string;\n description?: string;\n};\n\ninterface ColumnInternal {\n dataType?: string;\n columnType?: string;\n notNull?: boolean;\n hasDefault?: boolean;\n default?: unknown;\n defaultFn?: () => unknown;\n enumValues?: ReadonlyArray<string>;\n length?: number;\n precision?: number;\n scale?: number;\n primary?: boolean;\n isPrimaryKey?: boolean;\n primaryKey?: boolean;\n}\n\nfunction tableNameOf(table: unknown): string {\n if (table === null || typeof table !== \"object\") return \"<unknown>\";\n const sym = (table as Record<symbol, unknown>)[Symbol.for(\"drizzle:Name\")];\n if (typeof sym === \"string\") return sym;\n const inner = (table as { _?: { name?: string } })._;\n return inner?.name ?? \"<unknown>\";\n}\n\nfunction lower(s: string | undefined): string {\n return (s ?? \"\").toLowerCase();\n}\n\nfunction isInteger(dataType: string, columnType: string): boolean {\n if (dataType === \"number\" && /int/.test(columnType)) return true;\n if (dataType === \"integer\") return true;\n return false;\n}\n\ntype ColumnMatcher = (meta: ColumnInternal, dt: string, ct: string) => JsonSchema7Property | null;\n\nconst matchEnum: ColumnMatcher = (meta) =>\n Array.isArray(meta.enumValues) && meta.enumValues.length > 0\n ? { type: \"string\", enum: [...meta.enumValues] }\n : null;\n\nconst matchUuid: ColumnMatcher = (_m, _dt, ct) =>\n /uuid/.test(ct) ? { type: \"string\", format: \"uuid\" } : null;\n\nconst matchNumeric: ColumnMatcher = (meta, _dt, ct) => {\n if (!/numeric|decimal/.test(ct)) return null;\n const out: JsonSchema7Property = { type: \"string\", format: \"decimal\" };\n if (typeof meta.scale === \"number\" && meta.scale >= 0) {\n out.multipleOf = 10 ** -meta.scale;\n }\n return out;\n};\n\nconst matchBigint: ColumnMatcher = (_m, _dt, ct) =>\n /bigint/.test(ct) ? { type: \"string\", format: \"int64\" } : null;\n\nconst matchDate: ColumnMatcher = (_m, dt, ct) =>\n dt === \"date\" || /timestamp|date/.test(ct) ? { type: \"string\", format: \"date-time\" } : null;\n\nconst matchBlob: ColumnMatcher = (_m, _dt, ct) =>\n /blob|bytea|binary/.test(ct) ? { type: \"string\", contentEncoding: \"base64\" } : null;\n\nconst matchBoolean: ColumnMatcher = (_m, dt, ct) =>\n dt === \"boolean\" || /boolean|bool/.test(ct) ? { type: \"boolean\" } : null;\n\nconst matchJson: ColumnMatcher = (_m, dt, ct) =>\n dt === \"json\" || /json/.test(ct) ? { type: \"object\" } : null;\n\nconst matchInteger: ColumnMatcher = (_m, dt, ct) =>\n isInteger(dt, ct) ? { type: \"integer\" } : null;\n\nconst matchFloat: ColumnMatcher = (_m, dt, ct) =>\n dt === \"number\" || /real|double|float/.test(ct) ? { type: \"number\" } : null;\n\nconst matchString: ColumnMatcher = (meta, dt, ct) => {\n if (!(dt === \"string\" || /text|varchar|char/.test(ct))) return null;\n const out: JsonSchema7Property = { type: \"string\" };\n if (typeof meta.length === \"number\" && meta.length > 0) out.maxLength = meta.length;\n return out;\n};\n\nconst COLUMN_MATCHERS: readonly ColumnMatcher[] = [\n matchEnum,\n matchUuid,\n matchNumeric,\n matchBigint,\n matchDate,\n matchBlob,\n matchBoolean,\n matchJson,\n matchInteger,\n matchFloat,\n matchString,\n];\n\nfunction mapColumnToJsonSchema(\n colName: string,\n col: Column,\n tableName: string,\n): JsonSchema7Property {\n const meta = col as unknown as ColumnInternal;\n const dt = lower(meta.dataType);\n const ct = lower(meta.columnType);\n\n for (const matcher of COLUMN_MATCHERS) {\n const result = matcher(meta, dt, ct);\n if (result !== null) return result;\n }\n\n throw new OrmSchemaExportError(\n `Cannot export column \"${colName}\" of table \"${tableName}\": unknown type (dataType=\"${meta.dataType}\", columnType=\"${meta.columnType}\"). Add to mapColumnToJsonSchema or use the \"_excludeFromExport: true\" annotation.`,\n );\n}\n\nexport function exportSchema(table: Table): JsonSchema7 {\n const tableName = tableNameOf(table);\n const columns = getTableColumns(table) as Record<string, Column>;\n\n const properties: Record<string, JsonSchema7Property> = {};\n const required: string[] = [];\n\n for (const [colName, col] of Object.entries(columns)) {\n const meta = col as unknown as ColumnInternal;\n const prop = mapColumnToJsonSchema(colName, col, tableName);\n\n if (meta.hasDefault === true) {\n if (meta.default !== undefined) {\n prop.default = meta.default;\n }\n }\n\n if (meta.notNull === true && meta.hasDefault !== true) {\n required.push(colName);\n }\n\n properties[colName] = prop;\n }\n\n return {\n $schema: \"http://json-schema.org/draft-07/schema#\",\n title: tableName,\n type: \"object\",\n properties,\n required,\n additionalProperties: false,\n };\n}\n\nexport function exportSchemas(schema: Record<string, Table>): Record<string, JsonSchema7> {\n const out: Record<string, JsonSchema7> = {};\n for (const [, table] of Object.entries(schema)) {\n const name = tableNameOf(table);\n out[name] = exportSchema(table);\n }\n return out;\n}\n"]}
1
+ {"version":3,"sources":["../src/errors.ts","../src/schema-export.ts"],"names":["OrmError","Error","name","OrmSchemaExportError","tableNameOf","table","sym","Symbol","for","inner","_","lower","s","toLowerCase","isInteger","dataType","columnType","test","matchEnum","meta","Array","isArray","enumValues","length","type","enum","matchUuid","_m","_dt","ct","format","matchNumeric","out","scale","multipleOf","matchBigint","matchDate","dt","matchBlob","contentEncoding","matchBoolean","matchJson","matchInteger","matchFloat","matchString","maxLength","COLUMN_MATCHERS","mapColumnToJsonSchema","colName","col","tableName","matcher","result","exportSchema","columns","getTableColumns","properties","required","Object","entries","prop","hasDefault","default","undefined","notNull","push","$schema","title","additionalProperties","exportSchemas","schema"],"mappings":";;;;;;AAOO,IAAMA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AAAA,EAAAA,cAAAA,CAAAA;AA0CT,SAASgB,cAAcC,MAAAA,EAA6B;AACzD,EAAA,MAAMtC,MAAmC,EAAC;AAC1C,EAAA,KAAA,MAAW,GAAG3B,KAAAA,KAAUqD,MAAAA,CAAOC,OAAAA,CAAQW,MAAAA,CAAAA,EAAS;AAC9C,IAAA,MAAMpE,IAAAA,GAAOE,YAAYC,KAAAA,CAAAA;AACzB2B,IAAAA,GAAAA,CAAI9B,IAAAA,CAAAA,GAAQmD,YAAAA,CAAahD,KAAAA,CAAAA;AAC3B,EAAA;AACA,EAAA,OAAO2B,GAAAA;AACT;AAPgBqC,MAAAA,CAAAA,aAAAA,EAAAA,eAAAA,CAAAA","file":"schema-export.js","sourcesContent":["/**\n * Base class for every error this package raises.\n *\n * Catch this to handle anything from `@theokit/orm` without naming each subclass, and catch a\n * subclass when the response differs: a configuration fault needs a deploy, a validation fault\n * needs a different call.\n */\nexport class OrmError extends Error {\n override readonly name: string = \"OrmError\";\n}\n\n/**\n * The wiring is wrong, and no input will make the call succeed.\n *\n * Raised when an entity has no primary key, when `forFeature` runs before `forRoot` for its data\n * source, when `@Transactional` finds no DataSource bound to the instance, or when the handle\n * passed as `db` does not expose `transaction()`. Every case is a mistake in setup rather than in\n * the data, so it fails at the earliest point that can see it rather than at the first query.\n */\nexport class OrmConfigurationError extends OrmError {\n override readonly name = \"OrmConfigurationError\";\n}\n\n/**\n * A caller-supplied value was rejected at the boundary.\n *\n * The id guards are the reason this exists: `findById`, `update` and `delete` refuse a null, empty\n * or non-scalar id rather than passing it to Drizzle, because a `DELETE` whose `WHERE` matched\n * nothing usable is indistinguishable from one that matched everything until the rows are gone.\n */\nexport class OrmValidationError extends OrmError {\n override readonly name = \"OrmValidationError\";\n}\n\n/**\n * A table could not be expressed as JSON Schema.\n *\n * Raised by {@link exportSchema} for a column whose type has no mapping. It fails rather than\n * skipping the column: a consumer generating a model in another language would get one missing a\n * field and find out at the first insert.\n */\nexport class OrmSchemaExportError extends OrmError {\n override readonly name = \"OrmSchemaExportError\";\n}\n","import type { Column, Table } from \"drizzle-orm\";\nimport { getTableColumns } from \"drizzle-orm\";\nimport { OrmSchemaExportError } from \"./errors.js\";\n\n/**\n * A JSON Schema draft-07 object describing one table.\n *\n * This is the contract a non-TypeScript consumer reads. `additionalProperties` is fixed to `false`\n * so a generator in another language produces a closed model rather than one that silently accepts\n * columns this table does not have.\n */\nexport type JsonSchema7 = {\n $schema?: string;\n title?: string;\n type: \"object\";\n properties: Record<string, JsonSchema7Property>;\n required: string[];\n additionalProperties: false;\n};\n\n/**\n * One column, as JSON Schema draft-07 sees it.\n *\n * `x-check` is the one field outside the standard: it carries the SQL check constraint verbatim,\n * because draft-07 has no vocabulary for it and dropping it would let a generated model accept\n * values the database will reject.\n */\nexport type JsonSchema7Property = {\n type?: \"string\" | \"integer\" | \"number\" | \"boolean\" | \"object\" | \"array\" | \"null\";\n format?: string;\n maxLength?: number;\n multipleOf?: number;\n default?: unknown;\n enum?: ReadonlyArray<string | number>;\n contentEncoding?: string;\n \"x-check\"?: string;\n description?: string;\n};\n\ninterface ColumnInternal {\n dataType?: string;\n columnType?: string;\n notNull?: boolean;\n hasDefault?: boolean;\n default?: unknown;\n defaultFn?: () => unknown;\n enumValues?: ReadonlyArray<string>;\n length?: number;\n precision?: number;\n scale?: number;\n primary?: boolean;\n isPrimaryKey?: boolean;\n primaryKey?: boolean;\n}\n\nfunction tableNameOf(table: unknown): string {\n if (table === null || typeof table !== \"object\") return \"<unknown>\";\n const sym = (table as Record<symbol, unknown>)[Symbol.for(\"drizzle:Name\")];\n if (typeof sym === \"string\") return sym;\n const inner = (table as { _?: { name?: string } })._;\n return inner?.name ?? \"<unknown>\";\n}\n\nfunction lower(s: string | undefined): string {\n return (s ?? \"\").toLowerCase();\n}\n\nfunction isInteger(dataType: string, columnType: string): boolean {\n if (dataType === \"number\" && /int/.test(columnType)) return true;\n if (dataType === \"integer\") return true;\n return false;\n}\n\ntype ColumnMatcher = (meta: ColumnInternal, dt: string, ct: string) => JsonSchema7Property | null;\n\nconst matchEnum: ColumnMatcher = (meta) =>\n Array.isArray(meta.enumValues) && meta.enumValues.length > 0\n ? { type: \"string\", enum: [...meta.enumValues] }\n : null;\n\nconst matchUuid: ColumnMatcher = (_m, _dt, ct) =>\n /uuid/.test(ct) ? { type: \"string\", format: \"uuid\" } : null;\n\nconst matchNumeric: ColumnMatcher = (meta, _dt, ct) => {\n if (!/numeric|decimal/.test(ct)) return null;\n const out: JsonSchema7Property = { type: \"string\", format: \"decimal\" };\n if (typeof meta.scale === \"number\" && meta.scale >= 0) {\n out.multipleOf = 10 ** -meta.scale;\n }\n return out;\n};\n\nconst matchBigint: ColumnMatcher = (_m, _dt, ct) =>\n /bigint/.test(ct) ? { type: \"string\", format: \"int64\" } : null;\n\nconst matchDate: ColumnMatcher = (_m, dt, ct) =>\n dt === \"date\" || /timestamp|date/.test(ct) ? { type: \"string\", format: \"date-time\" } : null;\n\nconst matchBlob: ColumnMatcher = (_m, _dt, ct) =>\n /blob|bytea|binary/.test(ct) ? { type: \"string\", contentEncoding: \"base64\" } : null;\n\nconst matchBoolean: ColumnMatcher = (_m, dt, ct) =>\n dt === \"boolean\" || /boolean|bool/.test(ct) ? { type: \"boolean\" } : null;\n\nconst matchJson: ColumnMatcher = (_m, dt, ct) =>\n dt === \"json\" || /json/.test(ct) ? { type: \"object\" } : null;\n\nconst matchInteger: ColumnMatcher = (_m, dt, ct) =>\n isInteger(dt, ct) ? { type: \"integer\" } : null;\n\nconst matchFloat: ColumnMatcher = (_m, dt, ct) =>\n dt === \"number\" || /real|double|float/.test(ct) ? { type: \"number\" } : null;\n\nconst matchString: ColumnMatcher = (meta, dt, ct) => {\n if (!(dt === \"string\" || /text|varchar|char/.test(ct))) return null;\n const out: JsonSchema7Property = { type: \"string\" };\n if (typeof meta.length === \"number\" && meta.length > 0) out.maxLength = meta.length;\n return out;\n};\n\nconst COLUMN_MATCHERS: readonly ColumnMatcher[] = [\n matchEnum,\n matchUuid,\n matchNumeric,\n matchBigint,\n matchDate,\n matchBlob,\n matchBoolean,\n matchJson,\n matchInteger,\n matchFloat,\n matchString,\n];\n\nfunction mapColumnToJsonSchema(\n colName: string,\n col: Column,\n tableName: string,\n): JsonSchema7Property {\n const meta = col as unknown as ColumnInternal;\n const dt = lower(meta.dataType);\n const ct = lower(meta.columnType);\n\n for (const matcher of COLUMN_MATCHERS) {\n const result = matcher(meta, dt, ct);\n if (result !== null) return result;\n }\n\n throw new OrmSchemaExportError(\n `Cannot export column \"${colName}\" of table \"${tableName}\": unknown type (dataType=\"${meta.dataType}\", columnType=\"${meta.columnType}\"). Add to mapColumnToJsonSchema or use the \"_excludeFromExport: true\" annotation.`,\n );\n}\n\n/**\n * Emit the JSON Schema draft-07 description of one Drizzle table.\n *\n * A column is `required` when it is `NOT NULL` and has no default — the two together are what\n * decide whether a caller must supply a value, and treating `NOT NULL` alone as required would\n * demand values the database would have filled in.\n *\n * @throws {OrmSchemaExportError} when a column's type has no mapping. Emitting a partial schema\n * would be worse than failing: a consumer in another language would generate a model missing a\n * field and discover it at the first insert.\n */\nexport function exportSchema(table: Table): JsonSchema7 {\n const tableName = tableNameOf(table);\n const columns = getTableColumns(table) as Record<string, Column>;\n\n const properties: Record<string, JsonSchema7Property> = {};\n const required: string[] = [];\n\n for (const [colName, col] of Object.entries(columns)) {\n const meta = col as unknown as ColumnInternal;\n const prop = mapColumnToJsonSchema(colName, col, tableName);\n\n if (meta.hasDefault === true) {\n if (meta.default !== undefined) {\n prop.default = meta.default;\n }\n }\n\n if (meta.notNull === true && meta.hasDefault !== true) {\n required.push(colName);\n }\n\n properties[colName] = prop;\n }\n\n return {\n $schema: \"http://json-schema.org/draft-07/schema#\",\n title: tableName,\n type: \"object\",\n properties,\n required,\n additionalProperties: false,\n };\n}\n\n/**\n * Emit one schema per table, keyed by the table's name in the database rather than by the key it\n * has in the Drizzle schema object — the two differ whenever a table is declared as\n * `users: sqliteTable(\"app_users\", ...)`, and a consumer generating models needs the name the\n * database answers to.\n *\n * @throws {OrmSchemaExportError} from the first table that has an unmappable column.\n */\nexport function exportSchemas(schema: Record<string, Table>): Record<string, JsonSchema7> {\n const out: Record<string, JsonSchema7> = {};\n for (const [, table] of Object.entries(schema)) {\n const name = tableNameOf(table);\n out[name] = exportSchema(table);\n }\n return out;\n}\n"]}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@theokit/orm",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Repository pattern + @InjectRepository decorator + agent-aware columns + @Transactional + schema export polyglot over drizzle-orm, consuming @theokit/di for inversion of control. NestJS TypeORM-equivalent DX for the theokit ecosystem.",
5
5
  "license": "Apache-2.0",
6
- "homepage": "https://github.com/usetheo/theokit-sdk#readme",
7
- "bugs": "https://github.com/usetheo/theokit-sdk/issues",
6
+ "homepage": "https://github.com/usetheokit/theokit-di#readme",
7
+ "bugs": "https://github.com/usetheokit/theokit-di/issues",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/usetheo/theokit-sdk.git",
10
+ "url": "git+https://github.com/usetheokit/theokit-di.git",
11
11
  "directory": "packages/orm"
12
12
  },
13
13
  "type": "module",
@@ -46,12 +46,6 @@
46
46
  "LICENSE",
47
47
  "CHANGELOG.md"
48
48
  ],
49
- "scripts": {
50
- "build": "tsup",
51
- "typecheck": "tsc --noEmit",
52
- "test": "vitest run --passWithNoTests",
53
- "test:coverage": "vitest run --coverage --passWithNoTests"
54
- },
55
49
  "keywords": [
56
50
  "orm",
57
51
  "drizzle",
@@ -64,7 +58,7 @@
64
58
  "Theo"
65
59
  ],
66
60
  "peerDependencies": {
67
- "@theokit/di": "^0.1.0",
61
+ "@theokit/di": "^0.1.0 || ^0.2.0",
68
62
  "drizzle-orm": ">=0.36.0",
69
63
  "reflect-metadata": "^0.2.0"
70
64
  },
@@ -74,19 +68,30 @@
74
68
  }
75
69
  },
76
70
  "devDependencies": {
71
+ "@stryker-mutator/core": "^9.6.1",
72
+ "@stryker-mutator/vitest-runner": "^9.6.1",
77
73
  "@swc/core": "^1.15.40",
78
- "@theokit/di": "workspace:*",
79
74
  "@types/better-sqlite3": "^7.6.13",
80
75
  "@vitest/coverage-v8": "^4.1.8",
81
76
  "better-sqlite3": "^11.10.0",
82
77
  "drizzle-orm": "^0.36.4",
83
78
  "reflect-metadata": "^0.2.0",
84
79
  "tsup": "^8.5.0",
80
+ "typedoc": "^0.28.19",
85
81
  "typescript": "^5.8.0",
86
82
  "unplugin-swc": "^1.5.9",
87
- "vitest": "^4.1.8"
83
+ "vitest": "^4.1.8",
84
+ "@theokit/di": "0.2.0"
88
85
  },
89
86
  "publishConfig": {
90
- "access": "public"
87
+ "access": "public",
88
+ "provenance": true
89
+ },
90
+ "scripts": {
91
+ "build": "tsup",
92
+ "typecheck": "tsc --noEmit",
93
+ "test": "vitest run --passWithNoTests",
94
+ "test:coverage": "vitest run --coverage --passWithNoTests",
95
+ "docs:json": "typedoc --options typedoc.json"
91
96
  }
92
- }
97
+ }