@danielhritcu/zenstack-custom 1.1.0 → 1.2.1
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.
- package/dist/cli.cjs +93 -9
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +93 -9
- package/dist/cli.js.map +1 -1
- package/dist/codegen/index.cjs +82 -7
- package/dist/codegen/index.cjs.map +1 -1
- package/dist/codegen/index.d.cts +28 -8
- package/dist/codegen/index.d.ts +28 -8
- package/dist/codegen/index.js +82 -7
- package/dist/codegen/index.js.map +1 -1
- package/dist/{config-1Cdfs72F.d.cts → config-rukOeRbn.d.cts} +4 -1
- package/dist/{config-1Cdfs72F.d.ts → config-rukOeRbn.d.ts} +4 -1
- package/dist/index.cjs +82 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +82 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { D as DerivedField, a as DerivedModelDescriptor, E as ExtendedSchema, G as GlobalConfig, M as ManyRelation, b as ModelConfig, c as ModelsOutput, O as OneRelation, S as SchemaConfig, d as SearchField, e as SearchProfile, T as ThroughPath, f as ThroughRelation, Z as ZenConfig, g as defineConfig } from './config-
|
|
2
|
-
export { APP_SLUG_JS, APP_SLUG_SQL, ComputedFieldDeclaration, ComputedFieldInfo, ComputedFieldsConfig, DerivedModelDeclaration, DerivedModelsConfig, EmitSchemaOptions, EnumInfo, FKInfo, FKRelationInfo, FieldInfo, FilteredRelationDeclaration, FilteredRelationsConfig, GENERATED_FILE_BANNER, RelationField, ResolvedRelationTargets, SearchDefaultDeclaration, SearchDefaultsConfig, TableInfo, ThroughRelationDeclaration, ThroughRelationPath, ThroughRelationsConfig, TypeDefField, TypeDefInfo, TypeDefMapping, TypedJsonArtifacts, TypedJsonFieldInfo, ViewInfo, adaptToLegacyConfig, assertNoTypedColumnOverrides, buildRelations, buildTypeDefs, capitalize, defineModels, derived, discoverEnums, discoverTables, discoverViews, emitCompatTs, emitEnumBlock, emitEnumsTs, emitFieldBlock, emitGeneratedFileBanner, emitIndexTs, emitInputTs, emitJsonNamespaceBlock, emitJsonRawNamespaceBlock, emitJsonRawTs, emitJsonTs, emitModelsTs, emitOrmTypesTs, emitRelationField, emitSchemaTs, emitTypeDefsBlock, emitViewsTs, esc, extend, extractFKs, getDrizzleTableName, many, mapColumn, model, one, through, toPascalCase, uncapitalize, writeFileIfChanged } from './codegen/index.cjs';
|
|
1
|
+
export { D as DerivedField, a as DerivedModelDescriptor, E as ExtendedSchema, G as GlobalConfig, M as ManyRelation, b as ModelConfig, c as ModelsOutput, O as OneRelation, S as SchemaConfig, d as SearchField, e as SearchProfile, T as ThroughPath, f as ThroughRelation, Z as ZenConfig, g as defineConfig } from './config-rukOeRbn.cjs';
|
|
2
|
+
export { APP_SLUG_JS, APP_SLUG_SQL, BrandingInfo, ComputedFieldDeclaration, ComputedFieldInfo, ComputedFieldsConfig, DerivedModelDeclaration, DerivedModelsConfig, EmitSchemaOptions, EnumInfo, FKInfo, FKRelationInfo, FieldInfo, FilteredRelationDeclaration, FilteredRelationsConfig, GENERATED_FILE_BANNER, RelationField, ResolvedRelationTargets, SearchDefaultDeclaration, SearchDefaultsConfig, TableInfo, ThroughRelationDeclaration, ThroughRelationPath, ThroughRelationsConfig, TypeDefField, TypeDefInfo, TypeDefMapping, TypedJsonArtifacts, TypedJsonFieldInfo, ViewInfo, adaptToLegacyConfig, assertNoTypedColumnOverrides, buildRelations, buildTypeDefs, capitalize, defineModels, derived, discoverEnums, discoverTables, discoverViews, emitCompatTs, emitEnumBlock, emitEnumsTs, emitFieldBlock, emitGeneratedFileBanner, emitIndexTs, emitInputTs, emitJsonNamespaceBlock, emitJsonRawNamespaceBlock, emitJsonRawTs, emitJsonTs, emitModelsTs, emitOrmTypesTs, emitRelationField, emitSchemaTs, emitTypeDefsBlock, emitViewsTs, esc, extend, extractFKs, getDrizzleTableName, many, mapColumn, model, one, through, toPascalCase, uncapitalize, writeFileIfChanged } from './codegen/index.cjs';
|
|
3
3
|
export { ArgsBuilder, CategorizedChange, ChangeCategory, CronJobOpts, CustomHashes, CustomObject, CustomObjectEntry, CustomObjectType, CustomObjectsMap, ENUM_MAP, ExtensionOpts, FALSE, FunctionOpts, GenerateFlags, OrderIssue, PgCronJob, PgExtension, PgFunction, PgTrigger, PgTypes, TriggerEvent, TriggerForEach, TriggerFunction, TriggerFunctionOpts, TriggerOpts, TriggerTiming, appSlugForeignKey, auditColumns, categorizeChanges, cleanMeta, colAppSlug, colCreatedAt, colDeletedAt, colId, colNumeric, colTimestamp, colUpdatedAt, collectCustomObjects, computeHash, currentAppSlug, currentUser, custom, defaultPolicy, drop, fixOrder, formatChangeSummary, formatVerboseOutput, generate, generateDropSQL, getLatestSnapshotPath, hasAppSlug, hasBypassEnabled, loadSchemaModules, packToSgz, parseFlags, pgCron, pgExtension, pgFunction, pgOrmEnum, pgTrigger, pgTypes, readJournal, readSnapshotCustomObjects, serializeCustomObject, simpleDiff, syncMeta, toPgEnum, unpackFromSgz, validateOrder, validateTimestamps, writeSnapshotCustomObjects } from './drizzle/index.cjs';
|
|
4
4
|
import 'drizzle-orm/pg-core';
|
|
5
5
|
import 'drizzle-orm';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { D as DerivedField, a as DerivedModelDescriptor, E as ExtendedSchema, G as GlobalConfig, M as ManyRelation, b as ModelConfig, c as ModelsOutput, O as OneRelation, S as SchemaConfig, d as SearchField, e as SearchProfile, T as ThroughPath, f as ThroughRelation, Z as ZenConfig, g as defineConfig } from './config-
|
|
2
|
-
export { APP_SLUG_JS, APP_SLUG_SQL, ComputedFieldDeclaration, ComputedFieldInfo, ComputedFieldsConfig, DerivedModelDeclaration, DerivedModelsConfig, EmitSchemaOptions, EnumInfo, FKInfo, FKRelationInfo, FieldInfo, FilteredRelationDeclaration, FilteredRelationsConfig, GENERATED_FILE_BANNER, RelationField, ResolvedRelationTargets, SearchDefaultDeclaration, SearchDefaultsConfig, TableInfo, ThroughRelationDeclaration, ThroughRelationPath, ThroughRelationsConfig, TypeDefField, TypeDefInfo, TypeDefMapping, TypedJsonArtifacts, TypedJsonFieldInfo, ViewInfo, adaptToLegacyConfig, assertNoTypedColumnOverrides, buildRelations, buildTypeDefs, capitalize, defineModels, derived, discoverEnums, discoverTables, discoverViews, emitCompatTs, emitEnumBlock, emitEnumsTs, emitFieldBlock, emitGeneratedFileBanner, emitIndexTs, emitInputTs, emitJsonNamespaceBlock, emitJsonRawNamespaceBlock, emitJsonRawTs, emitJsonTs, emitModelsTs, emitOrmTypesTs, emitRelationField, emitSchemaTs, emitTypeDefsBlock, emitViewsTs, esc, extend, extractFKs, getDrizzleTableName, many, mapColumn, model, one, through, toPascalCase, uncapitalize, writeFileIfChanged } from './codegen/index.js';
|
|
1
|
+
export { D as DerivedField, a as DerivedModelDescriptor, E as ExtendedSchema, G as GlobalConfig, M as ManyRelation, b as ModelConfig, c as ModelsOutput, O as OneRelation, S as SchemaConfig, d as SearchField, e as SearchProfile, T as ThroughPath, f as ThroughRelation, Z as ZenConfig, g as defineConfig } from './config-rukOeRbn.js';
|
|
2
|
+
export { APP_SLUG_JS, APP_SLUG_SQL, BrandingInfo, ComputedFieldDeclaration, ComputedFieldInfo, ComputedFieldsConfig, DerivedModelDeclaration, DerivedModelsConfig, EmitSchemaOptions, EnumInfo, FKInfo, FKRelationInfo, FieldInfo, FilteredRelationDeclaration, FilteredRelationsConfig, GENERATED_FILE_BANNER, RelationField, ResolvedRelationTargets, SearchDefaultDeclaration, SearchDefaultsConfig, TableInfo, ThroughRelationDeclaration, ThroughRelationPath, ThroughRelationsConfig, TypeDefField, TypeDefInfo, TypeDefMapping, TypedJsonArtifacts, TypedJsonFieldInfo, ViewInfo, adaptToLegacyConfig, assertNoTypedColumnOverrides, buildRelations, buildTypeDefs, capitalize, defineModels, derived, discoverEnums, discoverTables, discoverViews, emitCompatTs, emitEnumBlock, emitEnumsTs, emitFieldBlock, emitGeneratedFileBanner, emitIndexTs, emitInputTs, emitJsonNamespaceBlock, emitJsonRawNamespaceBlock, emitJsonRawTs, emitJsonTs, emitModelsTs, emitOrmTypesTs, emitRelationField, emitSchemaTs, emitTypeDefsBlock, emitViewsTs, esc, extend, extractFKs, getDrizzleTableName, many, mapColumn, model, one, through, toPascalCase, uncapitalize, writeFileIfChanged } from './codegen/index.js';
|
|
3
3
|
export { ArgsBuilder, CategorizedChange, ChangeCategory, CronJobOpts, CustomHashes, CustomObject, CustomObjectEntry, CustomObjectType, CustomObjectsMap, ENUM_MAP, ExtensionOpts, FALSE, FunctionOpts, GenerateFlags, OrderIssue, PgCronJob, PgExtension, PgFunction, PgTrigger, PgTypes, TriggerEvent, TriggerForEach, TriggerFunction, TriggerFunctionOpts, TriggerOpts, TriggerTiming, appSlugForeignKey, auditColumns, categorizeChanges, cleanMeta, colAppSlug, colCreatedAt, colDeletedAt, colId, colNumeric, colTimestamp, colUpdatedAt, collectCustomObjects, computeHash, currentAppSlug, currentUser, custom, defaultPolicy, drop, fixOrder, formatChangeSummary, formatVerboseOutput, generate, generateDropSQL, getLatestSnapshotPath, hasAppSlug, hasBypassEnabled, loadSchemaModules, packToSgz, parseFlags, pgCron, pgExtension, pgFunction, pgOrmEnum, pgTrigger, pgTypes, readJournal, readSnapshotCustomObjects, serializeCustomObject, simpleDiff, syncMeta, toPgEnum, unpackFromSgz, validateOrder, validateTimestamps, writeSnapshotCustomObjects } from './drizzle/index.js';
|
|
4
4
|
import 'drizzle-orm/pg-core';
|
|
5
5
|
import 'drizzle-orm';
|
package/dist/index.js
CHANGED
|
@@ -138,7 +138,8 @@ function model(table, opts) {
|
|
|
138
138
|
search: opts.search,
|
|
139
139
|
defaultWhere: opts.defaultWhere,
|
|
140
140
|
derived: opts.derived,
|
|
141
|
-
validate: opts.validate
|
|
141
|
+
validate: opts.validate,
|
|
142
|
+
branded: opts.branded
|
|
142
143
|
};
|
|
143
144
|
}
|
|
144
145
|
__name(model, "model");
|
|
@@ -1850,6 +1851,32 @@ __name(sortTypedJsonFields, "sortTypedJsonFields");
|
|
|
1850
1851
|
|
|
1851
1852
|
// src/codegen/emit.ts
|
|
1852
1853
|
var DB_ATTR_RE = /@db\.(\w+)(?:\((\d+)\))?/;
|
|
1854
|
+
function isUuidField(t, fieldName) {
|
|
1855
|
+
const col = t.table[fieldName];
|
|
1856
|
+
if (!col) return false;
|
|
1857
|
+
return col.columnType === "PgUUID";
|
|
1858
|
+
}
|
|
1859
|
+
__name(isUuidField, "isUuidField");
|
|
1860
|
+
function isPkField(t, fieldName) {
|
|
1861
|
+
const col = t.table[fieldName];
|
|
1862
|
+
if (!col) return false;
|
|
1863
|
+
if (col.primary) return true;
|
|
1864
|
+
const sqlName = col.name;
|
|
1865
|
+
return t.cfg.primaryKeys.some((pk) => pk.columns.some((c) => c.name === sqlName));
|
|
1866
|
+
}
|
|
1867
|
+
__name(isPkField, "isPkField");
|
|
1868
|
+
function findFkTarget(t, fieldName, fkRelations) {
|
|
1869
|
+
const modelFks = fkRelations[t.modelName];
|
|
1870
|
+
if (!modelFks) return null;
|
|
1871
|
+
for (const fkInfo of Object.values(modelFks)) {
|
|
1872
|
+
const idx = fkInfo.fields.indexOf(fieldName);
|
|
1873
|
+
if (idx >= 0) {
|
|
1874
|
+
return fkInfo.targetExportName;
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
return null;
|
|
1878
|
+
}
|
|
1879
|
+
__name(findFkTarget, "findFkTarget");
|
|
1853
1880
|
function buildDerivedEnumName(modelName, fieldName) {
|
|
1854
1881
|
return `${toPascalCase(modelName)}${toPascalCase(fieldName)}`;
|
|
1855
1882
|
}
|
|
@@ -2345,8 +2372,9 @@ function emitSchemaTs({ tables, enumMap, modelRelations, inverseRelations, searc
|
|
|
2345
2372
|
return out.join("\n");
|
|
2346
2373
|
}
|
|
2347
2374
|
__name(emitSchemaTs, "emitSchemaTs");
|
|
2348
|
-
function emitModelsTs(tables, typedJsonFields = []) {
|
|
2375
|
+
function emitModelsTs(tables, typedJsonFields = [], branding) {
|
|
2349
2376
|
const jsonFieldAliases = createJsonFieldAliasMap(typedJsonFields);
|
|
2377
|
+
const hasBranding = branding && (Object.keys(branding.brandedFields).length > 0 || tables.some((t) => getEntityFieldNames(t).some((f) => isUuidField(t, f) && isPkField(t, f))));
|
|
2350
2378
|
const out = [
|
|
2351
2379
|
...emitGeneratedFileBanner()
|
|
2352
2380
|
];
|
|
@@ -2354,6 +2382,10 @@ function emitModelsTs(tables, typedJsonFields = []) {
|
|
|
2354
2382
|
out.push('import type * as $ from "@zenstackhq/orm";');
|
|
2355
2383
|
out.push('import type * as Json from "./json";');
|
|
2356
2384
|
out.push('import { type SchemaType as Schema } from "./schema";');
|
|
2385
|
+
if (hasBranding) {
|
|
2386
|
+
out.push("");
|
|
2387
|
+
out.push("declare const __brand: unique symbol;");
|
|
2388
|
+
}
|
|
2357
2389
|
out.push("");
|
|
2358
2390
|
for (const t of tables) {
|
|
2359
2391
|
out.push(`export interface ${t.typeName} extends $.ModelResult<Schema, ${esc(t.modelName)}> {}`);
|
|
@@ -2364,7 +2396,12 @@ function emitModelsTs(tables, typedJsonFields = []) {
|
|
|
2364
2396
|
if (jsonAlias) {
|
|
2365
2397
|
out.push(` export interface ${exportName} extends Json.${jsonAlias} {}`);
|
|
2366
2398
|
} else {
|
|
2367
|
-
|
|
2399
|
+
const brandedLine = branding ? emitBrandedFieldLine(t, fieldName, exportName, branding, " ") : null;
|
|
2400
|
+
if (brandedLine) {
|
|
2401
|
+
out.push(...brandedLine);
|
|
2402
|
+
} else {
|
|
2403
|
+
out.push(` export type ${exportName} = ${t.typeName}[${esc(fieldName)}];`);
|
|
2404
|
+
}
|
|
2368
2405
|
}
|
|
2369
2406
|
}
|
|
2370
2407
|
out.push("}");
|
|
@@ -2373,6 +2410,33 @@ function emitModelsTs(tables, typedJsonFields = []) {
|
|
|
2373
2410
|
return out.join("\n");
|
|
2374
2411
|
}
|
|
2375
2412
|
__name(emitModelsTs, "emitModelsTs");
|
|
2413
|
+
function emitBrandedFieldLine(t, fieldName, exportName, branding, indent2) {
|
|
2414
|
+
const customBranded = branding.brandedFields[t.modelName]?.[fieldName];
|
|
2415
|
+
if (isUuidField(t, fieldName) && isPkField(t, fieldName)) {
|
|
2416
|
+
const brand = `${t.modelName}.${fieldName}`;
|
|
2417
|
+
return [
|
|
2418
|
+
`${indent2}export type ${exportName} = string & { [__brand]: '${brand}' };`,
|
|
2419
|
+
`${indent2}export const ${exportName} = (id: string): ${exportName} => id as ${exportName};`
|
|
2420
|
+
];
|
|
2421
|
+
}
|
|
2422
|
+
if (isUuidField(t, fieldName)) {
|
|
2423
|
+
const targetExportName = findFkTarget(t, fieldName, branding.fkRelations);
|
|
2424
|
+
if (targetExportName) {
|
|
2425
|
+
return [
|
|
2426
|
+
`${indent2}export type ${exportName} = ${targetExportName}.Id;`
|
|
2427
|
+
];
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
if (customBranded) {
|
|
2431
|
+
const brand = `${t.modelName}.${fieldName}`;
|
|
2432
|
+
return [
|
|
2433
|
+
`${indent2}export type ${exportName} = string & { [__brand]: '${brand}' };`,
|
|
2434
|
+
`${indent2}export const ${exportName} = (id: string): ${exportName} => id as ${exportName};`
|
|
2435
|
+
];
|
|
2436
|
+
}
|
|
2437
|
+
return null;
|
|
2438
|
+
}
|
|
2439
|
+
__name(emitBrandedFieldLine, "emitBrandedFieldLine");
|
|
2376
2440
|
function emitViewsTs(views, typedJsonFields = []) {
|
|
2377
2441
|
const jsonFieldAliases = createJsonFieldAliasMap(typedJsonFields);
|
|
2378
2442
|
const out = [
|
|
@@ -2438,12 +2502,13 @@ function emitInputTs(tables) {
|
|
|
2438
2502
|
return out.join("\n");
|
|
2439
2503
|
}
|
|
2440
2504
|
__name(emitInputTs, "emitInputTs");
|
|
2441
|
-
function emitIndexTs({ tables, views, enumMap, typeDefs, typedJsonFields }) {
|
|
2505
|
+
function emitIndexTs({ tables, views, enumMap, typeDefs, typedJsonFields, branding }) {
|
|
2442
2506
|
const allEnums = new Map([
|
|
2443
2507
|
...enumMap,
|
|
2444
2508
|
...collectDerivedEnums(tables, enumMap)
|
|
2445
2509
|
]);
|
|
2446
2510
|
const jsonFieldAliases = createJsonFieldAliasMap(typedJsonFields);
|
|
2511
|
+
const hasBranding = branding && (Object.keys(branding.brandedFields).length > 0 || tables.some((t) => getEntityFieldNames(t).some((f) => isUuidField(t, f) && isPkField(t, f))));
|
|
2447
2512
|
const out = [
|
|
2448
2513
|
...emitGeneratedFileBanner()
|
|
2449
2514
|
];
|
|
@@ -2451,6 +2516,10 @@ function emitIndexTs({ tables, views, enumMap, typeDefs, typedJsonFields }) {
|
|
|
2451
2516
|
out.push('import type * as $ from "@zenstackhq/orm";');
|
|
2452
2517
|
out.push('import type * as RawJson from "../../supabase/schema/types";');
|
|
2453
2518
|
out.push('import { type SchemaType as Schema } from "./schema";');
|
|
2519
|
+
if (hasBranding) {
|
|
2520
|
+
out.push("");
|
|
2521
|
+
out.push("declare const __brand: unique symbol;");
|
|
2522
|
+
}
|
|
2454
2523
|
out.push("");
|
|
2455
2524
|
out.push("export namespace Json {");
|
|
2456
2525
|
out.push(...emitJsonNamespaceBlock(typeDefs, typedJsonFields, " "));
|
|
@@ -2465,7 +2534,7 @@ function emitIndexTs({ tables, views, enumMap, typeDefs, typedJsonFields }) {
|
|
|
2465
2534
|
out.push("");
|
|
2466
2535
|
out.push("export namespace Table {");
|
|
2467
2536
|
for (const table of tables) {
|
|
2468
|
-
out.push(...emitEntityNamespaceBlock(table, table.modelName, jsonFieldAliases, " "));
|
|
2537
|
+
out.push(...emitEntityNamespaceBlock(table, table.modelName, jsonFieldAliases, " ", branding));
|
|
2469
2538
|
out.push("");
|
|
2470
2539
|
}
|
|
2471
2540
|
out.push("}");
|
|
@@ -2624,7 +2693,7 @@ function createJsonFieldAliasMap(typedJsonFields) {
|
|
|
2624
2693
|
]));
|
|
2625
2694
|
}
|
|
2626
2695
|
__name(createJsonFieldAliasMap, "createJsonFieldAliasMap");
|
|
2627
|
-
function emitEntityNamespaceBlock(entity, modelName, jsonFieldAliases, indent2 = "") {
|
|
2696
|
+
function emitEntityNamespaceBlock(entity, modelName, jsonFieldAliases, indent2 = "", branding) {
|
|
2628
2697
|
const out = [];
|
|
2629
2698
|
out.push(`${indent2}export interface ${entity.typeName} extends $.ModelResult<Schema, ${esc(modelName)}> {}`);
|
|
2630
2699
|
out.push(`${indent2}export namespace ${entity.typeName} {`);
|
|
@@ -2634,7 +2703,13 @@ function emitEntityNamespaceBlock(entity, modelName, jsonFieldAliases, indent2 =
|
|
|
2634
2703
|
if (jsonAlias) {
|
|
2635
2704
|
out.push(`${indent2} export interface ${exportName} extends Json.${jsonAlias} {}`);
|
|
2636
2705
|
} else {
|
|
2637
|
-
|
|
2706
|
+
const isTable = "table" in entity;
|
|
2707
|
+
const brandedLine = isTable && branding ? emitBrandedFieldLine(entity, fieldName, exportName, branding, `${indent2} `) : null;
|
|
2708
|
+
if (brandedLine) {
|
|
2709
|
+
out.push(...brandedLine);
|
|
2710
|
+
} else {
|
|
2711
|
+
out.push(`${indent2} export type ${exportName} = ${entity.typeName}[${esc(fieldName)}];`);
|
|
2712
|
+
}
|
|
2638
2713
|
}
|
|
2639
2714
|
}
|
|
2640
2715
|
out.push(`${indent2}}`);
|