@nest-yalc-2/omnikernel-module 1.1.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.
- package/LICENSE +661 -0
- package/README.md +193 -0
- package/package.json +52 -0
- package/src/__tests__/omni-collection.entity.spec.ts +49 -0
- package/src/__tests__/omni-collection.service.spec.ts +83 -0
- package/src/__tests__/omni-document.entity.spec.ts +55 -0
- package/src/__tests__/omni-document.service.spec.ts +83 -0
- package/src/__tests__/omni-extension-projection-constraints.spec.ts +518 -0
- package/src/__tests__/omni-extension-projection.registration.spec.ts +946 -0
- package/src/__tests__/omni-extension-projection.service.spec.ts +806 -0
- package/src/__tests__/omni-external-ref.entity.spec.ts +36 -0
- package/src/__tests__/omni-external-ref.service.spec.ts +252 -0
- package/src/__tests__/omni-named.entity.spec.ts +33 -0
- package/src/__tests__/omni-record.entity.spec.ts +32 -0
- package/src/__tests__/omni-record.service.spec.ts +107 -0
- package/src/__tests__/omni-relation-semantics.spec.ts +102 -0
- package/src/__tests__/omni-relation.entity.spec.ts +38 -0
- package/src/__tests__/omni-scope-substrate.spec.ts +81 -0
- package/src/__tests__/omni-scoped.backend.spec.ts +115 -0
- package/src/__tests__/omni-scoped.service.spec.ts +354 -0
- package/src/__tests__/omnikernel.diagnostics.spec.ts +94 -0
- package/src/__tests__/omnikernel.module.spec.ts +40 -0
- package/src/__tests__/omnikernel.persistence.spec.ts +154 -0
- package/src/__tests__/omnikernel.public-api.spec.ts +238 -0
- package/src/__tests__/omnikernel.query.service.spec.ts +155 -0
- package/src/__tests__/tsconfig.json +6 -0
- package/src/base/omni-base.entity.d.ts +9 -0
- package/src/base/omni-base.entity.js +53 -0
- package/src/base/omni-base.entity.js.map +1 -0
- package/src/base/omni-base.entity.ts +41 -0
- package/src/base/omni-external-ref.entity.d.ts +13 -0
- package/src/base/omni-external-ref.entity.js +72 -0
- package/src/base/omni-external-ref.entity.js.map +1 -0
- package/src/base/omni-external-ref.entity.ts +53 -0
- package/src/base/omni-named.entity.d.ts +6 -0
- package/src/base/omni-named.entity.js +35 -0
- package/src/base/omni-named.entity.js.map +1 -0
- package/src/base/omni-named.entity.ts +16 -0
- package/src/base/omni-record.entity.d.ts +13 -0
- package/src/base/omni-record.entity.js +71 -0
- package/src/base/omni-record.entity.js.map +1 -0
- package/src/base/omni-record.entity.ts +51 -0
- package/src/base/omni-relation.entity.d.ts +15 -0
- package/src/base/omni-relation.entity.js +91 -0
- package/src/base/omni-relation.entity.js.map +1 -0
- package/src/base/omni-relation.entity.ts +72 -0
- package/src/index.d.ts +49 -0
- package/src/index.js +66 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +49 -0
- package/src/omni-collection-kind.enum.d.ts +4 -0
- package/src/omni-collection-kind.enum.js +13 -0
- package/src/omni-collection-kind.enum.js.map +1 -0
- package/src/omni-collection-kind.enum.ts +10 -0
- package/src/omni-collection.backend.d.ts +2 -0
- package/src/omni-collection.backend.js +15 -0
- package/src/omni-collection.backend.js.map +1 -0
- package/src/omni-collection.backend.ts +16 -0
- package/src/omni-collection.dto.d.ts +32 -0
- package/src/omni-collection.dto.js +184 -0
- package/src/omni-collection.dto.js.map +1 -0
- package/src/omni-collection.dto.ts +170 -0
- package/src/omni-collection.entity.d.ts +7 -0
- package/src/omni-collection.entity.js +41 -0
- package/src/omni-collection.entity.js.map +1 -0
- package/src/omni-collection.entity.ts +21 -0
- package/src/omni-collection.service.d.ts +14 -0
- package/src/omni-collection.service.js +24 -0
- package/src/omni-collection.service.js.map +1 -0
- package/src/omni-collection.service.ts +75 -0
- package/src/omni-document-kind.enum.d.ts +6 -0
- package/src/omni-document-kind.enum.js +15 -0
- package/src/omni-document-kind.enum.js.map +1 -0
- package/src/omni-document-kind.enum.ts +12 -0
- package/src/omni-document.backend.d.ts +2 -0
- package/src/omni-document.backend.js +15 -0
- package/src/omni-document.backend.js.map +1 -0
- package/src/omni-document.backend.ts +16 -0
- package/src/omni-document.dto.d.ts +35 -0
- package/src/omni-document.dto.js +213 -0
- package/src/omni-document.dto.js.map +1 -0
- package/src/omni-document.dto.ts +198 -0
- package/src/omni-document.entity.d.ts +10 -0
- package/src/omni-document.entity.js +53 -0
- package/src/omni-document.entity.js.map +1 -0
- package/src/omni-document.entity.ts +30 -0
- package/src/omni-document.service.d.ts +14 -0
- package/src/omni-document.service.js +24 -0
- package/src/omni-document.service.js.map +1 -0
- package/src/omni-document.service.ts +75 -0
- package/src/omni-dto.helpers.d.ts +1 -0
- package/src/omni-dto.helpers.js +10 -0
- package/src/omni-dto.helpers.js.map +1 -0
- package/src/omni-dto.helpers.ts +21 -0
- package/src/omni-extension-projection.definition.d.ts +17 -0
- package/src/omni-extension-projection.definition.js +160 -0
- package/src/omni-extension-projection.definition.js.map +1 -0
- package/src/omni-extension-projection.definition.ts +294 -0
- package/src/omni-extension-projection.resource.d.ts +42 -0
- package/src/omni-extension-projection.resource.js +127 -0
- package/src/omni-extension-projection.resource.js.map +1 -0
- package/src/omni-extension-projection.resource.ts +274 -0
- package/src/omni-extension-projection.service.d.ts +33 -0
- package/src/omni-extension-projection.service.js +332 -0
- package/src/omni-extension-projection.service.js.map +1 -0
- package/src/omni-extension-projection.service.ts +452 -0
- package/src/omni-external-ref-binding.validator.d.ts +14 -0
- package/src/omni-external-ref-binding.validator.js +34 -0
- package/src/omni-external-ref-binding.validator.js.map +1 -0
- package/src/omni-external-ref-binding.validator.ts +53 -0
- package/src/omni-external-ref-internal-type.enum.d.ts +5 -0
- package/src/omni-external-ref-internal-type.enum.js +14 -0
- package/src/omni-external-ref-internal-type.enum.js.map +1 -0
- package/src/omni-external-ref-internal-type.enum.ts +11 -0
- package/src/omni-external-ref.backend.d.ts +2 -0
- package/src/omni-external-ref.backend.js +19 -0
- package/src/omni-external-ref.backend.js.map +1 -0
- package/src/omni-external-ref.backend.ts +25 -0
- package/src/omni-external-ref.dto.d.ts +26 -0
- package/src/omni-external-ref.dto.js +140 -0
- package/src/omni-external-ref.dto.js.map +1 -0
- package/src/omni-external-ref.dto.ts +128 -0
- package/src/omni-external-ref.service.d.ts +33 -0
- package/src/omni-external-ref.service.js +133 -0
- package/src/omni-external-ref.service.js.map +1 -0
- package/src/omni-external-ref.service.ts +255 -0
- package/src/omni-migration.d.ts +28 -0
- package/src/omni-migration.js +239 -0
- package/src/omni-migration.js.map +1 -0
- package/src/omni-migration.ts +365 -0
- package/src/omni-named.backend.d.ts +2 -0
- package/src/omni-named.backend.js +13 -0
- package/src/omni-named.backend.js.map +1 -0
- package/src/omni-named.backend.ts +11 -0
- package/src/omni-named.dto.d.ts +19 -0
- package/src/omni-named.dto.js +94 -0
- package/src/omni-named.dto.js.map +1 -0
- package/src/omni-named.dto.ts +86 -0
- package/src/omni-projection.catalog.d.ts +49 -0
- package/src/omni-projection.catalog.js +177 -0
- package/src/omni-projection.catalog.js.map +1 -0
- package/src/omni-projection.catalog.ts +345 -0
- package/src/omni-projection.lifecycle.d.ts +20 -0
- package/src/omni-projection.lifecycle.js +3 -0
- package/src/omni-projection.lifecycle.js.map +1 -0
- package/src/omni-projection.lifecycle.ts +53 -0
- package/src/omni-record-status.enum.d.ts +5 -0
- package/src/omni-record-status.enum.js +14 -0
- package/src/omni-record-status.enum.js.map +1 -0
- package/src/omni-record-status.enum.ts +11 -0
- package/src/omni-record.backend.d.ts +2 -0
- package/src/omni-record.backend.js +13 -0
- package/src/omni-record.backend.js.map +1 -0
- package/src/omni-record.backend.ts +19 -0
- package/src/omni-record.dto.d.ts +29 -0
- package/src/omni-record.dto.js +169 -0
- package/src/omni-record.dto.js.map +1 -0
- package/src/omni-record.dto.ts +157 -0
- package/src/omni-record.service.d.ts +18 -0
- package/src/omni-record.service.js +45 -0
- package/src/omni-record.service.js.map +1 -0
- package/src/omni-record.service.ts +113 -0
- package/src/omni-relation-kind.contract.d.ts +9 -0
- package/src/omni-relation-kind.contract.js +33 -0
- package/src/omni-relation-kind.contract.js.map +1 -0
- package/src/omni-relation-kind.contract.ts +49 -0
- package/src/omni-relation-kind.enum.d.ts +6 -0
- package/src/omni-relation-kind.enum.js +15 -0
- package/src/omni-relation-kind.enum.js.map +1 -0
- package/src/omni-relation-kind.enum.ts +12 -0
- package/src/omni-relation-projection.definition.d.ts +25 -0
- package/src/omni-relation-projection.definition.js +83 -0
- package/src/omni-relation-projection.definition.js.map +1 -0
- package/src/omni-relation-projection.definition.ts +166 -0
- package/src/omni-relation-projection.resource.d.ts +51 -0
- package/src/omni-relation-projection.resource.js +203 -0
- package/src/omni-relation-projection.resource.js.map +1 -0
- package/src/omni-relation-projection.resource.ts +360 -0
- package/src/omni-relation-projection.service.d.ts +47 -0
- package/src/omni-relation-projection.service.js +385 -0
- package/src/omni-relation-projection.service.js.map +1 -0
- package/src/omni-relation-projection.service.ts +610 -0
- package/src/omni-relation-semantics.d.ts +11 -0
- package/src/omni-relation-semantics.js +34 -0
- package/src/omni-relation-semantics.js.map +1 -0
- package/src/omni-relation-semantics.ts +52 -0
- package/src/omni-relation-status.enum.d.ts +5 -0
- package/src/omni-relation-status.enum.js +14 -0
- package/src/omni-relation-status.enum.js.map +1 -0
- package/src/omni-relation-status.enum.ts +11 -0
- package/src/omni-relation.backend.d.ts +2 -0
- package/src/omni-relation.backend.js +17 -0
- package/src/omni-relation.backend.js.map +1 -0
- package/src/omni-relation.backend.ts +21 -0
- package/src/omni-relation.dto.d.ts +28 -0
- package/src/omni-relation.dto.js +153 -0
- package/src/omni-relation.dto.js.map +1 -0
- package/src/omni-relation.dto.ts +142 -0
- package/src/omni-relation.service.d.ts +19 -0
- package/src/omni-relation.service.js +76 -0
- package/src/omni-relation.service.js.map +1 -0
- package/src/omni-relation.service.ts +159 -0
- package/src/omni-scope.d.ts +33 -0
- package/src/omni-scope.js +91 -0
- package/src/omni-scope.js.map +1 -0
- package/src/omni-scope.ts +161 -0
- package/src/omni-scoped.backend.d.ts +21 -0
- package/src/omni-scoped.backend.js +47 -0
- package/src/omni-scoped.backend.js.map +1 -0
- package/src/omni-scoped.backend.ts +110 -0
- package/src/omni-scoped.repository.d.ts +10 -0
- package/src/omni-scoped.repository.js +26 -0
- package/src/omni-scoped.repository.js.map +1 -0
- package/src/omni-scoped.repository.ts +34 -0
- package/src/omni-scoped.service.d.ts +36 -0
- package/src/omni-scoped.service.js +171 -0
- package/src/omni-scoped.service.js.map +1 -0
- package/src/omni-scoped.service.ts +338 -0
- package/src/omnikernel.diagnostics.d.ts +16 -0
- package/src/omnikernel.diagnostics.js +50 -0
- package/src/omnikernel.diagnostics.js.map +1 -0
- package/src/omnikernel.diagnostics.ts +83 -0
- package/src/omnikernel.module.d.ts +5 -0
- package/src/omnikernel.module.js +87 -0
- package/src/omnikernel.module.js.map +1 -0
- package/src/omnikernel.module.ts +97 -0
- package/src/omnikernel.query.service.d.ts +17 -0
- package/src/omnikernel.query.service.js +85 -0
- package/src/omnikernel.query.service.js.map +1 -0
- package/src/omnikernel.query.service.ts +108 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import type { DataSource, EntityTarget, ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { Table, TableForeignKey, type TableOptions } from 'typeorm';
|
|
3
|
+
import {
|
|
4
|
+
createProjectionDialect,
|
|
5
|
+
type ProjectionResourceDefinition,
|
|
6
|
+
} from '@nest-yalc-2/crud-gen';
|
|
7
|
+
import { OmniExternalRefEntity } from './base/omni-external-ref.entity.js';
|
|
8
|
+
import { OmniNamedEntity } from './base/omni-named.entity.js';
|
|
9
|
+
import { OmniRecordEntity } from './base/omni-record.entity.js';
|
|
10
|
+
import { OmniRelationEntity } from './base/omni-relation.entity.js';
|
|
11
|
+
import { OmniCollectionEntity } from './omni-collection.entity.js';
|
|
12
|
+
import { OmniDocumentEntity } from './omni-document.entity.js';
|
|
13
|
+
|
|
14
|
+
export interface OmniMigrationSnapshot {
|
|
15
|
+
/** A migration-owned identifier, for example `omni-v1`. */
|
|
16
|
+
readonly version: string;
|
|
17
|
+
/** The driver whose physical column types were captured. */
|
|
18
|
+
readonly dialect: 'sqlite' | 'postgres';
|
|
19
|
+
/** Immutable, serializable TypeORM TableOptions captured during authoring. */
|
|
20
|
+
readonly tables: readonly TableOptions[];
|
|
21
|
+
/** Immutable ProjectionDialect DDL for JSON/expression indexes. */
|
|
22
|
+
readonly indexStatements: readonly string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The portable subset of a migration runner used by an Omni migration plan.
|
|
27
|
+
*
|
|
28
|
+
* It deliberately does not reference TypeORM's `QueryRunner` type. A package
|
|
29
|
+
* manager may give the module and a consuming migration distinct physical
|
|
30
|
+
* TypeORM installations, even at the same version; exposing that branded
|
|
31
|
+
* framework type would then reject the application's runner. TypeORM runners
|
|
32
|
+
* satisfy this structural capability contract without a consumer cast.
|
|
33
|
+
*/
|
|
34
|
+
export interface OmniMigrationRunner {
|
|
35
|
+
createTable(
|
|
36
|
+
table: unknown,
|
|
37
|
+
ifNotExist?: boolean,
|
|
38
|
+
createForeignKeys?: boolean,
|
|
39
|
+
createIndices?: boolean,
|
|
40
|
+
): Promise<void>;
|
|
41
|
+
query(statement: string): Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface OmniMigrationPlan {
|
|
45
|
+
readonly version: string;
|
|
46
|
+
readonly tableNames: readonly string[];
|
|
47
|
+
/** Dialect-compiled index DDL that the plan executes after all tables exist. */
|
|
48
|
+
readonly indexStatements: readonly string[];
|
|
49
|
+
/** Returns fresh mutable Table instances from the versioned source snapshot. */
|
|
50
|
+
createTables(): Table[];
|
|
51
|
+
/** Intended only from a TypeORM migration up() method. */
|
|
52
|
+
create(queryRunner: OmniMigrationRunner): Promise<void>;
|
|
53
|
+
/** Intended only from a TypeORM migration down() method. */
|
|
54
|
+
drop(queryRunner: OmniMigrationRunner): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The migration-relevant subset of a registered extension composition. It
|
|
59
|
+
* keeps schema authoring tied to the same immutable projection definition as
|
|
60
|
+
* the generated transport and service, without making runtime metadata a
|
|
61
|
+
* migration dependency.
|
|
62
|
+
*/
|
|
63
|
+
export interface OmniMigrationExtensionRegistration {
|
|
64
|
+
readonly entities: readonly EntityTarget<any>[];
|
|
65
|
+
readonly definition: ProjectionResourceDefinition;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const omniBaseEntities = [
|
|
69
|
+
OmniNamedEntity,
|
|
70
|
+
OmniRecordEntity,
|
|
71
|
+
OmniDocumentEntity,
|
|
72
|
+
OmniCollectionEntity,
|
|
73
|
+
OmniRelationEntity,
|
|
74
|
+
OmniExternalRefEntity,
|
|
75
|
+
] as const;
|
|
76
|
+
|
|
77
|
+
function freezeDeep<T>(value: T): T {
|
|
78
|
+
if (value && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
79
|
+
for (const child of Object.values(value as Record<string, unknown>)) {
|
|
80
|
+
freezeDeep(child);
|
|
81
|
+
}
|
|
82
|
+
Object.freeze(value);
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function dialectFor(dataSource: DataSource): 'sqlite' | 'postgres' {
|
|
88
|
+
if (dataSource.options.type === 'sqlite') return 'sqlite';
|
|
89
|
+
if (dataSource.options.type === 'postgres') return 'postgres';
|
|
90
|
+
throw new TypeError('Omni migration snapshots support SQLite or PostgreSQL.');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function tableOptions(table: Table): TableOptions {
|
|
94
|
+
return {
|
|
95
|
+
database: table.database,
|
|
96
|
+
schema: table.schema,
|
|
97
|
+
name: table.name,
|
|
98
|
+
withoutRowid: table.withoutRowid,
|
|
99
|
+
engine: table.engine,
|
|
100
|
+
comment: table.comment,
|
|
101
|
+
columns: table.columns.map((column) => ({
|
|
102
|
+
name: column.name,
|
|
103
|
+
type: column.type,
|
|
104
|
+
default: column.default,
|
|
105
|
+
onUpdate: column.onUpdate,
|
|
106
|
+
isNullable: column.isNullable,
|
|
107
|
+
isGenerated: column.isGenerated,
|
|
108
|
+
generationStrategy: column.generationStrategy,
|
|
109
|
+
isPrimary: column.isPrimary,
|
|
110
|
+
isUnique: column.isUnique,
|
|
111
|
+
isArray: column.isArray,
|
|
112
|
+
comment: column.comment,
|
|
113
|
+
length: column.length,
|
|
114
|
+
width: column.width,
|
|
115
|
+
charset: column.charset,
|
|
116
|
+
collation: column.collation,
|
|
117
|
+
precision: column.precision,
|
|
118
|
+
scale: column.scale,
|
|
119
|
+
zerofill: column.zerofill,
|
|
120
|
+
unsigned: column.unsigned,
|
|
121
|
+
enum: column.enum ? [...column.enum] : undefined,
|
|
122
|
+
enumName: column.enumName,
|
|
123
|
+
primaryKeyConstraintName: column.primaryKeyConstraintName,
|
|
124
|
+
asExpression: column.asExpression,
|
|
125
|
+
generatedType: column.generatedType,
|
|
126
|
+
generatedIdentity: column.generatedIdentity,
|
|
127
|
+
spatialFeatureType: column.spatialFeatureType,
|
|
128
|
+
srid: column.srid,
|
|
129
|
+
})),
|
|
130
|
+
indices: table.indices.map((index) => ({
|
|
131
|
+
name: index.name,
|
|
132
|
+
columnNames: [...index.columnNames],
|
|
133
|
+
isUnique: index.isUnique,
|
|
134
|
+
isSpatial: index.isSpatial,
|
|
135
|
+
isConcurrent: index.isConcurrent,
|
|
136
|
+
isFulltext: index.isFulltext,
|
|
137
|
+
isNullFiltered: index.isNullFiltered,
|
|
138
|
+
parser: index.parser,
|
|
139
|
+
where: index.where,
|
|
140
|
+
})),
|
|
141
|
+
foreignKeys: table.foreignKeys.map((foreignKey) => ({
|
|
142
|
+
name: foreignKey.name,
|
|
143
|
+
columnNames: [...foreignKey.columnNames],
|
|
144
|
+
referencedDatabase: foreignKey.referencedDatabase,
|
|
145
|
+
referencedSchema: foreignKey.referencedSchema,
|
|
146
|
+
referencedTableName: foreignKey.referencedTableName,
|
|
147
|
+
referencedColumnNames: [...foreignKey.referencedColumnNames],
|
|
148
|
+
onDelete: foreignKey.onDelete,
|
|
149
|
+
onUpdate: foreignKey.onUpdate,
|
|
150
|
+
deferrable: foreignKey.deferrable,
|
|
151
|
+
})),
|
|
152
|
+
uniques: table.uniques.map((unique) => ({
|
|
153
|
+
name: unique.name,
|
|
154
|
+
columnNames: [...unique.columnNames],
|
|
155
|
+
deferrable: unique.deferrable,
|
|
156
|
+
})),
|
|
157
|
+
checks: table.checks.map((check) => ({
|
|
158
|
+
name: check.name,
|
|
159
|
+
columnNames: check.columnNames ? [...check.columnNames] : undefined,
|
|
160
|
+
expression: check.expression,
|
|
161
|
+
})),
|
|
162
|
+
exclusions: table.exclusions.map((exclusion) => ({
|
|
163
|
+
name: exclusion.name,
|
|
164
|
+
expression: exclusion.expression,
|
|
165
|
+
})),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function tableSnapshots(
|
|
170
|
+
dataSource: DataSource,
|
|
171
|
+
entities: readonly EntityTarget<ObjectLiteral>[],
|
|
172
|
+
): TableOptions[] {
|
|
173
|
+
const byTableName = new Map<string, Table>();
|
|
174
|
+
for (const entity of entities) {
|
|
175
|
+
const metadata = dataSource.getMetadata(entity);
|
|
176
|
+
const table = Table.create(metadata, dataSource.driver);
|
|
177
|
+
table.foreignKeys = metadata.foreignKeys.map((foreignKey) =>
|
|
178
|
+
TableForeignKey.create(foreignKey, dataSource.driver),
|
|
179
|
+
);
|
|
180
|
+
const current = byTableName.get(table.name);
|
|
181
|
+
if (!current || current.columns.length < table.columns.length) {
|
|
182
|
+
byTableName.set(table.name, table);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return orderTablesTopologically([...byTableName.values()].map(tableOptions));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Orders a complete migration snapshot from FK parents to children. A
|
|
191
|
+
* migration may not defer this to registration order: PostgreSQL requires the
|
|
192
|
+
* referenced table to exist at FK creation time. Self references are valid;
|
|
193
|
+
* cross-table cycles are rejected during migration authoring.
|
|
194
|
+
*/
|
|
195
|
+
function orderTablesTopologically(
|
|
196
|
+
tables: readonly TableOptions[],
|
|
197
|
+
): TableOptions[] {
|
|
198
|
+
const byName = new Map<string, TableOptions>();
|
|
199
|
+
for (const table of tables) {
|
|
200
|
+
if (!table.name)
|
|
201
|
+
throw new TypeError('Omni migration table name is required.');
|
|
202
|
+
byName.set(table.name, table);
|
|
203
|
+
}
|
|
204
|
+
const dependencies = new Map<string, Set<string>>();
|
|
205
|
+
for (const table of tables) {
|
|
206
|
+
const tableName = table.name!;
|
|
207
|
+
const parents = new Set<string>();
|
|
208
|
+
for (const foreignKey of table.foreignKeys ?? []) {
|
|
209
|
+
const parent = foreignKey.referencedTableName;
|
|
210
|
+
if (!parent || parent === tableName) continue;
|
|
211
|
+
if (!byName.has(parent)) {
|
|
212
|
+
throw new TypeError(
|
|
213
|
+
`Omni migration table ${tableName} references ${parent}, which is absent from this snapshot.`,
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
parents.add(parent);
|
|
217
|
+
}
|
|
218
|
+
dependencies.set(tableName, parents);
|
|
219
|
+
}
|
|
220
|
+
const remaining = new Map(
|
|
221
|
+
[...dependencies.entries()].map(([name, parents]) => [
|
|
222
|
+
name,
|
|
223
|
+
new Set(parents),
|
|
224
|
+
]),
|
|
225
|
+
);
|
|
226
|
+
const ordered: TableOptions[] = [];
|
|
227
|
+
while (remaining.size > 0) {
|
|
228
|
+
const ready = tables.filter(
|
|
229
|
+
(table) =>
|
|
230
|
+
table.name !== undefined && remaining.get(table.name)?.size === 0,
|
|
231
|
+
);
|
|
232
|
+
if (ready.length === 0) {
|
|
233
|
+
throw new TypeError(
|
|
234
|
+
`Omni migration snapshot has a cross-table foreign-key cycle: ${[
|
|
235
|
+
...remaining.keys(),
|
|
236
|
+
].join(', ')}.`,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
for (const table of ready) {
|
|
240
|
+
const name = table.name!;
|
|
241
|
+
remaining.delete(name);
|
|
242
|
+
ordered.push(table);
|
|
243
|
+
for (const parents of remaining.values()) parents.delete(name);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return ordered;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function quotedIdentifier(identifier: string): string {
|
|
250
|
+
return `"${identifier.replaceAll('"', '""')}"`;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function quotedTableName(table: TableOptions): string {
|
|
254
|
+
if (!table.name)
|
|
255
|
+
throw new TypeError('Omni migration table name is required.');
|
|
256
|
+
return [table.schema, table.name]
|
|
257
|
+
.filter(
|
|
258
|
+
(part): part is string => typeof part === 'string' && part.length > 0,
|
|
259
|
+
)
|
|
260
|
+
.map(quotedIdentifier)
|
|
261
|
+
.join('.');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Authoring-only helper. Run this against a metadata-only DataSource and copy
|
|
266
|
+
* the returned value into a versioned migration source using
|
|
267
|
+
* defineOmniMigrationSnapshot. Never invoke it from a migration at runtime.
|
|
268
|
+
*/
|
|
269
|
+
export function captureOmniMigrationSnapshot(
|
|
270
|
+
version: string,
|
|
271
|
+
dataSource: DataSource,
|
|
272
|
+
extensions: readonly OmniMigrationExtensionRegistration[] = [],
|
|
273
|
+
): OmniMigrationSnapshot {
|
|
274
|
+
const dialect = dialectFor(dataSource);
|
|
275
|
+
return defineOmniMigrationSnapshot({
|
|
276
|
+
version,
|
|
277
|
+
dialect,
|
|
278
|
+
tables: tableSnapshots(dataSource, [
|
|
279
|
+
...omniBaseEntities,
|
|
280
|
+
...extensions.flatMap((extension) => extension.entities),
|
|
281
|
+
]),
|
|
282
|
+
indexStatements: extensions.flatMap((extension) =>
|
|
283
|
+
createProjectionDialect(dialect).compileIndexStatements(
|
|
284
|
+
extension.definition,
|
|
285
|
+
),
|
|
286
|
+
),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Freezes a migration-owned table snapshot. Old migration source calls this
|
|
292
|
+
* with a literal captured at authoring time, so future entity changes cannot
|
|
293
|
+
* alter its DDL.
|
|
294
|
+
*/
|
|
295
|
+
export function defineOmniMigrationSnapshot(
|
|
296
|
+
snapshot: OmniMigrationSnapshot,
|
|
297
|
+
): OmniMigrationSnapshot {
|
|
298
|
+
if (
|
|
299
|
+
typeof snapshot.version !== 'string' ||
|
|
300
|
+
snapshot.version.trim().length === 0
|
|
301
|
+
) {
|
|
302
|
+
throw new TypeError('Omni migration snapshot version is required.');
|
|
303
|
+
}
|
|
304
|
+
if (snapshot.dialect !== 'sqlite' && snapshot.dialect !== 'postgres') {
|
|
305
|
+
throw new TypeError('Omni migration snapshot dialect is unsupported.');
|
|
306
|
+
}
|
|
307
|
+
if (!Array.isArray(snapshot.tables) || snapshot.tables.length === 0) {
|
|
308
|
+
throw new TypeError('Omni migration snapshot requires at least one table.');
|
|
309
|
+
}
|
|
310
|
+
const names = snapshot.tables.map((table) => table.name);
|
|
311
|
+
if (
|
|
312
|
+
names.some((name) => typeof name !== 'string' || name.length === 0) ||
|
|
313
|
+
new Set(names).size !== names.length
|
|
314
|
+
) {
|
|
315
|
+
throw new TypeError('Omni migration snapshot table names must be unique.');
|
|
316
|
+
}
|
|
317
|
+
if (
|
|
318
|
+
!Array.isArray(snapshot.indexStatements) ||
|
|
319
|
+
snapshot.indexStatements.some(
|
|
320
|
+
(statement) =>
|
|
321
|
+
typeof statement !== 'string' || statement.trim().length === 0,
|
|
322
|
+
) ||
|
|
323
|
+
new Set(snapshot.indexStatements).size !== snapshot.indexStatements.length
|
|
324
|
+
) {
|
|
325
|
+
throw new TypeError(
|
|
326
|
+
'Omni migration snapshot index statements must be unique non-empty strings.',
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
return freezeDeep(structuredClone(snapshot));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Creates a migration executor from an already-versioned snapshot. This API
|
|
334
|
+
* deliberately accepts no DataSource or entity classes: runtime metadata is
|
|
335
|
+
* never a migration authority.
|
|
336
|
+
*/
|
|
337
|
+
export function createOmniMigrationPlan(
|
|
338
|
+
snapshot: OmniMigrationSnapshot,
|
|
339
|
+
): OmniMigrationPlan {
|
|
340
|
+
const source = defineOmniMigrationSnapshot(snapshot);
|
|
341
|
+
const tables = orderTablesTopologically(source.tables);
|
|
342
|
+
|
|
343
|
+
return Object.freeze({
|
|
344
|
+
version: source.version,
|
|
345
|
+
tableNames: Object.freeze(tables.map((table) => table.name)),
|
|
346
|
+
indexStatements: Object.freeze([...source.indexStatements]),
|
|
347
|
+
createTables: () =>
|
|
348
|
+
tables.map((table) => new Table(structuredClone(table))),
|
|
349
|
+
create: async (queryRunner: OmniMigrationRunner) => {
|
|
350
|
+
for (const table of tables) {
|
|
351
|
+
await queryRunner.createTable(new Table(structuredClone(table)));
|
|
352
|
+
}
|
|
353
|
+
for (const statement of source.indexStatements) {
|
|
354
|
+
await queryRunner.query(statement);
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
drop: async (queryRunner: OmniMigrationRunner) => {
|
|
358
|
+
for (const table of [...tables].reverse()) {
|
|
359
|
+
await queryRunner.query(
|
|
360
|
+
`DROP TABLE IF EXISTS ${quotedTableName(table)}`,
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.omniNamedBackendProvidersFactory = void 0;
|
|
4
|
+
const omni_named_entity_js_1 = require("./base/omni-named.entity.js");
|
|
5
|
+
const omni_scoped_backend_js_1 = require("./omni-scoped.backend.js");
|
|
6
|
+
const omni_scoped_service_js_1 = require("./omni-scoped.service.js");
|
|
7
|
+
const omniNamedBackendProvidersFactory = (dbConnection) => (0, omni_scoped_backend_js_1.omniScopedBackendProvidersFactory)({
|
|
8
|
+
entityModel: omni_named_entity_js_1.OmniNamedEntity,
|
|
9
|
+
dbConnection,
|
|
10
|
+
createService: (repository, scope, options) => new omni_scoped_service_js_1.OmniScopedService(repository, scope, options.deletion.named),
|
|
11
|
+
});
|
|
12
|
+
exports.omniNamedBackendProvidersFactory = omniNamedBackendProvidersFactory;
|
|
13
|
+
//# sourceMappingURL=omni-named.backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omni-named.backend.js","sourceRoot":"","sources":["omni-named.backend.ts"],"names":[],"mappings":";;;AAAA,sEAA8D;AAC9D,qEAA6E;AAC7E,qEAA6D;AAEtD,MAAM,gCAAgC,GAAG,CAAC,YAAoB,EAAE,EAAE,CACvE,IAAA,0DAAiC,EAAkB;IACjD,WAAW,EAAE,sCAAe;IAC5B,YAAY;IACZ,aAAa,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAC5C,IAAI,0CAAiB,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;CACnE,CAAC,CAAC;AANQ,QAAA,gCAAgC,oCAMxC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OmniNamedEntity } from './base/omni-named.entity.js';
|
|
2
|
+
import { omniScopedBackendProvidersFactory } from './omni-scoped.backend.js';
|
|
3
|
+
import { OmniScopedService } from './omni-scoped.service.js';
|
|
4
|
+
|
|
5
|
+
export const omniNamedBackendProvidersFactory = (dbConnection: string) =>
|
|
6
|
+
omniScopedBackendProvidersFactory<OmniNamedEntity>({
|
|
7
|
+
entityModel: OmniNamedEntity,
|
|
8
|
+
dbConnection,
|
|
9
|
+
createService: (repository, scope, options) =>
|
|
10
|
+
new OmniScopedService(repository, scope, options.deletion.named),
|
|
11
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OmniNamedEntity } from './base/omni-named.entity.js';
|
|
2
|
+
export declare class OmniNamedType extends OmniNamedEntity {
|
|
3
|
+
constructor(data?: Partial<OmniNamedType>);
|
|
4
|
+
guid: string;
|
|
5
|
+
revision: number;
|
|
6
|
+
externalId?: string | null;
|
|
7
|
+
title: string;
|
|
8
|
+
slug?: string | null;
|
|
9
|
+
}
|
|
10
|
+
declare const OmniNamedCreateInput_base: import("@nestjs/common").Type<Omit<OmniNamedType, "revision" | "createdAt" | "updatedAt">>;
|
|
11
|
+
export declare class OmniNamedCreateInput extends OmniNamedCreateInput_base {
|
|
12
|
+
}
|
|
13
|
+
declare const OmniNamedCondition_base: import("@nestjs/common").Type<Partial<OmniNamedCreateInput>>;
|
|
14
|
+
export declare class OmniNamedCondition extends OmniNamedCondition_base {
|
|
15
|
+
}
|
|
16
|
+
declare const OmniNamedUpdateInput_base: import("@nestjs/common").Type<Partial<OmniNamedCreateInput>>;
|
|
17
|
+
export declare class OmniNamedUpdateInput extends OmniNamedUpdateInput_base {
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.OmniNamedUpdateInput = exports.OmniNamedCondition = exports.OmniNamedCreateInput = exports.OmniNamedType = void 0;
|
|
16
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
17
|
+
const object_decorator_js_1 = require("@nest-yalc-2/crud-gen/object.decorator.js");
|
|
18
|
+
const uuid_scalar_js_1 = require("@nest-yalc-2/graphql/scalars/uuid.scalar.js");
|
|
19
|
+
const returnValue_js_1 = __importDefault(require("@nest-yalc-2/utils/returnValue.js"));
|
|
20
|
+
const class_validator_1 = require("class-validator");
|
|
21
|
+
const omni_named_entity_js_1 = require("./base/omni-named.entity.js");
|
|
22
|
+
const omni_dto_helpers_js_1 = require("./omni-dto.helpers.js");
|
|
23
|
+
let OmniNamedType = class OmniNamedType extends omni_named_entity_js_1.OmniNamedEntity {
|
|
24
|
+
constructor(data) {
|
|
25
|
+
super();
|
|
26
|
+
if (data) {
|
|
27
|
+
(0, omni_dto_helpers_js_1.assignOmniPublicDto)(this, data);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.OmniNamedType = OmniNamedType;
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, object_decorator_js_1.ModelField)({ gqlType: (0, returnValue_js_1.default)(uuid_scalar_js_1.UUIDScalar), isRequired: true }),
|
|
34
|
+
(0, class_validator_1.IsUUID)(),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], OmniNamedType.prototype, "guid", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, object_decorator_js_1.ModelField)({ gqlType: (0, returnValue_js_1.default)(graphql_1.Int) }),
|
|
39
|
+
(0, class_validator_1.IsInt)(),
|
|
40
|
+
__metadata("design:type", Number)
|
|
41
|
+
], OmniNamedType.prototype, "revision", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, object_decorator_js_1.ModelField)({
|
|
44
|
+
gqlType: (0, returnValue_js_1.default)(String),
|
|
45
|
+
gqlOptions: { nullable: true },
|
|
46
|
+
}),
|
|
47
|
+
(0, class_validator_1.IsOptional)(),
|
|
48
|
+
(0, class_validator_1.IsString)(),
|
|
49
|
+
(0, class_validator_1.MaxLength)(128),
|
|
50
|
+
__metadata("design:type", Object)
|
|
51
|
+
], OmniNamedType.prototype, "externalId", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, object_decorator_js_1.ModelField)({ gqlType: (0, returnValue_js_1.default)(String) }),
|
|
54
|
+
(0, class_validator_1.IsString)(),
|
|
55
|
+
(0, class_validator_1.MaxLength)(255),
|
|
56
|
+
__metadata("design:type", String)
|
|
57
|
+
], OmniNamedType.prototype, "title", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
(0, object_decorator_js_1.ModelField)({
|
|
60
|
+
gqlType: (0, returnValue_js_1.default)(String),
|
|
61
|
+
gqlOptions: { nullable: true },
|
|
62
|
+
}),
|
|
63
|
+
(0, class_validator_1.IsOptional)(),
|
|
64
|
+
(0, class_validator_1.IsString)(),
|
|
65
|
+
(0, class_validator_1.MaxLength)(255),
|
|
66
|
+
__metadata("design:type", Object)
|
|
67
|
+
], OmniNamedType.prototype, "slug", void 0);
|
|
68
|
+
exports.OmniNamedType = OmniNamedType = __decorate([
|
|
69
|
+
(0, graphql_1.ObjectType)(),
|
|
70
|
+
(0, object_decorator_js_1.ModelObject)(),
|
|
71
|
+
__metadata("design:paramtypes", [Object])
|
|
72
|
+
], OmniNamedType);
|
|
73
|
+
let OmniNamedCreateInput = class OmniNamedCreateInput extends (0, graphql_1.OmitType)(OmniNamedType, ['createdAt', 'updatedAt', 'revision'], graphql_1.InputType) {
|
|
74
|
+
};
|
|
75
|
+
exports.OmniNamedCreateInput = OmniNamedCreateInput;
|
|
76
|
+
exports.OmniNamedCreateInput = OmniNamedCreateInput = __decorate([
|
|
77
|
+
(0, graphql_1.InputType)(),
|
|
78
|
+
(0, object_decorator_js_1.ModelObject)()
|
|
79
|
+
], OmniNamedCreateInput);
|
|
80
|
+
let OmniNamedCondition = class OmniNamedCondition extends (0, graphql_1.PartialType)(OmniNamedCreateInput, graphql_1.InputType) {
|
|
81
|
+
};
|
|
82
|
+
exports.OmniNamedCondition = OmniNamedCondition;
|
|
83
|
+
exports.OmniNamedCondition = OmniNamedCondition = __decorate([
|
|
84
|
+
(0, graphql_1.InputType)(),
|
|
85
|
+
(0, object_decorator_js_1.ModelObject)({ copyFrom: OmniNamedType })
|
|
86
|
+
], OmniNamedCondition);
|
|
87
|
+
let OmniNamedUpdateInput = class OmniNamedUpdateInput extends (0, graphql_1.PartialType)(OmniNamedCreateInput, graphql_1.InputType) {
|
|
88
|
+
};
|
|
89
|
+
exports.OmniNamedUpdateInput = OmniNamedUpdateInput;
|
|
90
|
+
exports.OmniNamedUpdateInput = OmniNamedUpdateInput = __decorate([
|
|
91
|
+
(0, graphql_1.InputType)(),
|
|
92
|
+
(0, object_decorator_js_1.ModelObject)({ copyFrom: OmniNamedType })
|
|
93
|
+
], OmniNamedUpdateInput);
|
|
94
|
+
//# sourceMappingURL=omni-named.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omni-named.dto.js","sourceRoot":"","sources":["omni-named.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAMyB;AACzB,mFAGmD;AACnD,gFAAyE;AACzE,uFAA4D;AAC5D,qDAMyB;AACzB,sEAA8D;AAC9D,+DAA4D;AAIrD,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,sCAAe;IAChD,YAAY,IAA6B;QACvC,KAAK,EAAE,CAAC;QACR,IAAI,IAAI,EAAE,CAAC;YACT,IAAA,yCAAmB,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CAgCF,CAAA;AAtCY,sCAAa;AAUxB;IAFC,IAAA,gCAAU,EAAC,EAAE,OAAO,EAAE,IAAA,wBAAW,EAAC,2BAAU,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAClE,IAAA,wBAAM,GAAE;;2CACK;AAId;IAFC,IAAA,gCAAU,EAAC,EAAE,OAAO,EAAE,IAAA,wBAAW,EAAC,aAAG,CAAC,EAAE,CAAC;IACzC,IAAA,uBAAK,GAAE;;+CACU;AASlB;IAPC,IAAA,gCAAU,EAAC;QACV,OAAO,EAAE,IAAA,wBAAW,EAAC,MAAM,CAAC;QAC5B,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;KAC/B,CAAC;IACD,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,GAAG,CAAC;;iDACY;AAK3B;IAHC,IAAA,gCAAU,EAAC,EAAE,OAAO,EAAE,IAAA,wBAAW,EAAC,MAAM,CAAC,EAAE,CAAC;IAC5C,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,GAAG,CAAC;;4CACA;AASf;IAPC,IAAA,gCAAU,EAAC;QACV,OAAO,EAAE,IAAA,wBAAW,EAAC,MAAM,CAAC;QAC5B,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;KAC/B,CAAC;IACD,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,GAAG,CAAC;;2CACM;wBArCV,aAAa;IAFzB,IAAA,oBAAU,GAAE;IACZ,IAAA,iCAAW,GAAE;;GACD,aAAa,CAsCzB;AAIM,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,IAAA,kBAAQ,EAChD,aAAa,EACb,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,CAAU,EAC/C,mBAAS,CACV;CAAG,CAAA;AAJS,oDAAoB;+BAApB,oBAAoB;IAFhC,IAAA,mBAAS,GAAE;IACX,IAAA,iCAAW,GAAE;GACD,oBAAoB,CAI7B;AAIG,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,IAAA,qBAAW,EACjD,oBAAoB,EACpB,mBAAS,CACV;CAAG,CAAA;AAHS,gDAAkB;6BAAlB,kBAAkB;IAF9B,IAAA,mBAAS,GAAE;IACX,IAAA,iCAAW,EAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;GAC5B,kBAAkB,CAG3B;AAIG,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,IAAA,qBAAW,EACnD,oBAAoB,EACpB,mBAAS,CACV;CAAG,CAAA;AAHS,oDAAoB;+BAApB,oBAAoB;IAFhC,IAAA,mBAAS,GAAE;IACX,IAAA,iCAAW,EAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;GAC5B,oBAAoB,CAG7B"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InputType,
|
|
3
|
+
Int,
|
|
4
|
+
ObjectType,
|
|
5
|
+
OmitType,
|
|
6
|
+
PartialType,
|
|
7
|
+
} from '@nestjs/graphql';
|
|
8
|
+
import {
|
|
9
|
+
ModelField,
|
|
10
|
+
ModelObject,
|
|
11
|
+
} from '@nest-yalc-2/crud-gen/object.decorator.js';
|
|
12
|
+
import { UUIDScalar } from '@nest-yalc-2/graphql/scalars/uuid.scalar.js';
|
|
13
|
+
import returnValue from '@nest-yalc-2/utils/returnValue.js';
|
|
14
|
+
import {
|
|
15
|
+
IsInt,
|
|
16
|
+
IsOptional,
|
|
17
|
+
IsString,
|
|
18
|
+
IsUUID,
|
|
19
|
+
MaxLength,
|
|
20
|
+
} from 'class-validator';
|
|
21
|
+
import { OmniNamedEntity } from './base/omni-named.entity.js';
|
|
22
|
+
import { assignOmniPublicDto } from './omni-dto.helpers.js';
|
|
23
|
+
|
|
24
|
+
@ObjectType()
|
|
25
|
+
@ModelObject()
|
|
26
|
+
export class OmniNamedType extends OmniNamedEntity {
|
|
27
|
+
constructor(data?: Partial<OmniNamedType>) {
|
|
28
|
+
super();
|
|
29
|
+
if (data) {
|
|
30
|
+
assignOmniPublicDto(this, data);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@ModelField({ gqlType: returnValue(UUIDScalar), isRequired: true })
|
|
35
|
+
@IsUUID()
|
|
36
|
+
guid!: string;
|
|
37
|
+
|
|
38
|
+
@ModelField({ gqlType: returnValue(Int) })
|
|
39
|
+
@IsInt()
|
|
40
|
+
revision!: number;
|
|
41
|
+
|
|
42
|
+
@ModelField({
|
|
43
|
+
gqlType: returnValue(String),
|
|
44
|
+
gqlOptions: { nullable: true },
|
|
45
|
+
})
|
|
46
|
+
@IsOptional()
|
|
47
|
+
@IsString()
|
|
48
|
+
@MaxLength(128)
|
|
49
|
+
externalId?: string | null;
|
|
50
|
+
|
|
51
|
+
@ModelField({ gqlType: returnValue(String) })
|
|
52
|
+
@IsString()
|
|
53
|
+
@MaxLength(255)
|
|
54
|
+
title!: string;
|
|
55
|
+
|
|
56
|
+
@ModelField({
|
|
57
|
+
gqlType: returnValue(String),
|
|
58
|
+
gqlOptions: { nullable: true },
|
|
59
|
+
})
|
|
60
|
+
@IsOptional()
|
|
61
|
+
@IsString()
|
|
62
|
+
@MaxLength(255)
|
|
63
|
+
slug?: string | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@InputType()
|
|
67
|
+
@ModelObject()
|
|
68
|
+
export class OmniNamedCreateInput extends OmitType(
|
|
69
|
+
OmniNamedType,
|
|
70
|
+
['createdAt', 'updatedAt', 'revision'] as const,
|
|
71
|
+
InputType,
|
|
72
|
+
) {}
|
|
73
|
+
|
|
74
|
+
@InputType()
|
|
75
|
+
@ModelObject({ copyFrom: OmniNamedType })
|
|
76
|
+
export class OmniNamedCondition extends PartialType(
|
|
77
|
+
OmniNamedCreateInput,
|
|
78
|
+
InputType,
|
|
79
|
+
) {}
|
|
80
|
+
|
|
81
|
+
@InputType()
|
|
82
|
+
@ModelObject({ copyFrom: OmniNamedType })
|
|
83
|
+
export class OmniNamedUpdateInput extends PartialType(
|
|
84
|
+
OmniNamedCreateInput,
|
|
85
|
+
InputType,
|
|
86
|
+
) {}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { InjectionToken, Provider } from '@nestjs/common';
|
|
2
|
+
import { type EntityManager, type EntityTarget, type ObjectLiteral } from 'typeorm';
|
|
3
|
+
import { OmniRelationEntity } from './base/omni-relation.entity.js';
|
|
4
|
+
import type { OmniExtensionProjectionDefinition } from './omni-extension-projection.definition.js';
|
|
5
|
+
import { type OmniRelationProjectionDefinition } from './omni-relation-projection.definition.js';
|
|
6
|
+
import type { OmniScope } from './omni-scope.js';
|
|
7
|
+
export interface OmniExtensionProjectionReaderRegistration<Entity extends ObjectLiteral = ObjectLiteral> {
|
|
8
|
+
readonly type: 'extension';
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly entity: EntityTarget<Entity>;
|
|
11
|
+
readonly definition: OmniExtensionProjectionDefinition;
|
|
12
|
+
}
|
|
13
|
+
export interface OmniRelationProjectionReaderRegistration {
|
|
14
|
+
readonly type: 'relation';
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly definition: OmniRelationProjectionDefinition;
|
|
17
|
+
}
|
|
18
|
+
export type OmniProjectionReaderRegistration = OmniExtensionProjectionReaderRegistration | OmniRelationProjectionReaderRegistration;
|
|
19
|
+
export interface OmniExtensionProjectionReader<Entity extends ObjectLiteral = ObjectLiteral> {
|
|
20
|
+
get(guid: string): Promise<Entity | undefined>;
|
|
21
|
+
list(options?: {
|
|
22
|
+
where?: Readonly<Record<string, unknown>>;
|
|
23
|
+
take?: number;
|
|
24
|
+
}): Promise<Entity[]>;
|
|
25
|
+
}
|
|
26
|
+
export interface OmniRelationProjectionReader {
|
|
27
|
+
get(guid: string): Promise<OmniRelationEntity | undefined>;
|
|
28
|
+
list(options?: {
|
|
29
|
+
sourceRecordId?: string;
|
|
30
|
+
targetRecordId?: string;
|
|
31
|
+
take?: number;
|
|
32
|
+
}): Promise<OmniRelationEntity[]>;
|
|
33
|
+
}
|
|
34
|
+
export interface OmniProjectionTransactionReaders {
|
|
35
|
+
extension<Entity extends ObjectLiteral = ObjectLiteral>(id: string): OmniExtensionProjectionReader<Entity>;
|
|
36
|
+
relation(id: string): OmniRelationProjectionReader;
|
|
37
|
+
}
|
|
38
|
+
export interface OmniProjectionReaderCatalog {
|
|
39
|
+
bind(manager: EntityManager, scope: OmniScope): OmniProjectionTransactionReaders;
|
|
40
|
+
}
|
|
41
|
+
export interface OmniProjectionReaderCatalogProvider {
|
|
42
|
+
readonly token: InjectionToken<OmniProjectionReaderCatalog>;
|
|
43
|
+
}
|
|
44
|
+
export interface OmniProjectionReaderCatalogSource {
|
|
45
|
+
readonly reader: OmniProjectionReaderRegistration;
|
|
46
|
+
}
|
|
47
|
+
export declare const OMNI_PROJECTION_READER_CATALOG: unique symbol;
|
|
48
|
+
export declare function createOmniProjectionReaderCatalog(registrations: readonly (OmniProjectionReaderRegistration | OmniProjectionReaderCatalogSource)[]): OmniProjectionReaderCatalog;
|
|
49
|
+
export declare function createOmniProjectionReaderCatalogProvider(registrations: readonly (OmniProjectionReaderRegistration | OmniProjectionReaderCatalogSource)[], token?: InjectionToken<OmniProjectionReaderCatalog>): Provider;
|