@drzl/analyzer 1.11.0 → 1.12.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/dist/index.cjs +11 -0
- package/dist/index.d.cts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +10 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
SchemaAnalyzer: () => SchemaAnalyzer,
|
|
34
34
|
default: () => index_default,
|
|
35
35
|
describeV1Column: () => describeV1Column,
|
|
36
|
+
isReadOnlyRelation: () => isReadOnlyRelation,
|
|
36
37
|
isRelationsV2: () => isRelationsV2,
|
|
37
38
|
readRelationsV2: () => readRelationsV2
|
|
38
39
|
});
|
|
@@ -228,6 +229,12 @@ function getSymbolOf(target, key) {
|
|
|
228
229
|
}
|
|
229
230
|
return target[Symbol.for(key)];
|
|
230
231
|
}
|
|
232
|
+
function isReadOnlyRelation(val) {
|
|
233
|
+
if (!val || typeof val !== "object") return false;
|
|
234
|
+
return Object.getOwnPropertySymbols(val).some(
|
|
235
|
+
(sym) => String(sym.description).includes("MaterializedViewConfig")
|
|
236
|
+
);
|
|
237
|
+
}
|
|
231
238
|
function isRelationsV2(val) {
|
|
232
239
|
if (!val || typeof val !== "object" || Array.isArray(val)) return false;
|
|
233
240
|
const entries = Object.values(val);
|
|
@@ -757,6 +764,9 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
757
764
|
indexes: [...pkCols.length ? [{ columns: pkCols }] : [], ...indexes],
|
|
758
765
|
checks,
|
|
759
766
|
foreignKeys,
|
|
767
|
+
// A materialized view refuses every write, so the generators skip its insert and update
|
|
768
|
+
// schemas rather than describe an operation the database will always reject.
|
|
769
|
+
...isReadOnlyRelation(tbl) ? { readOnly: true } : {},
|
|
760
770
|
meta: {}
|
|
761
771
|
};
|
|
762
772
|
}
|
|
@@ -957,6 +967,7 @@ var index_default = SchemaAnalyzer;
|
|
|
957
967
|
0 && (module.exports = {
|
|
958
968
|
SchemaAnalyzer,
|
|
959
969
|
describeV1Column,
|
|
970
|
+
isReadOnlyRelation,
|
|
960
971
|
isRelationsV2,
|
|
961
972
|
readRelationsV2
|
|
962
973
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -182,6 +182,12 @@ interface Table {
|
|
|
182
182
|
indexes: Index[];
|
|
183
183
|
checks?: Check[];
|
|
184
184
|
foreignKeys?: ForeignKey[];
|
|
185
|
+
/**
|
|
186
|
+
* Set when the relation refuses writes, which today means a materialized view. Insert and
|
|
187
|
+
* update schemas are not emitted for one, because the database will always refuse the
|
|
188
|
+
* operation they describe.
|
|
189
|
+
*/
|
|
190
|
+
readOnly?: boolean;
|
|
185
191
|
meta?: Record<string, unknown>;
|
|
186
192
|
}
|
|
187
193
|
interface Enum {
|
|
@@ -223,6 +229,18 @@ declare function describeV1Column(column: any): Partial<Column> | null;
|
|
|
223
229
|
* `relations` record whose entries carry a `relationType`. That is specific enough not to
|
|
224
230
|
* collide with a table or an enum, both of which are checked before this.
|
|
225
231
|
*/
|
|
232
|
+
/**
|
|
233
|
+
* Whether a relation refuses writes outright.
|
|
234
|
+
*
|
|
235
|
+
* A materialized view does: `INSERT INTO mv ...` fails with `cannot change materialized view`,
|
|
236
|
+
* verified against Postgres. An insert or update schema for one describes an operation the
|
|
237
|
+
* database will always refuse.
|
|
238
|
+
*
|
|
239
|
+
* An ordinary view is deliberately not included. Postgres accepts an INSERT into a simple
|
|
240
|
+
* auto-updatable view, and whether a given view qualifies depends on its query rather than on
|
|
241
|
+
* anything the schema file states, so refusing them all would take away something that works.
|
|
242
|
+
*/
|
|
243
|
+
declare function isReadOnlyRelation(val: any): boolean;
|
|
226
244
|
declare function isRelationsV2(val: any): boolean;
|
|
227
245
|
/**
|
|
228
246
|
* Read the relations declared by `defineRelations`.
|
|
@@ -338,4 +356,4 @@ declare class SchemaAnalyzer {
|
|
|
338
356
|
analyze(opts?: AnalyzeOptions): Promise<Analysis>;
|
|
339
357
|
}
|
|
340
358
|
|
|
341
|
-
export { type Analysis, type AnalyzeOptions, type Check, type Column, type ColumnRef, type ColumnShape, type Dialect, type Enum, type ForeignKey, type Index, type Issue, type Key, type Relation, SchemaAnalyzer, type Table, SchemaAnalyzer as default, describeV1Column, isRelationsV2, readRelationsV2 };
|
|
359
|
+
export { type Analysis, type AnalyzeOptions, type Check, type Column, type ColumnRef, type ColumnShape, type Dialect, type Enum, type ForeignKey, type Index, type Issue, type Key, type Relation, SchemaAnalyzer, type Table, SchemaAnalyzer as default, describeV1Column, isReadOnlyRelation, isRelationsV2, readRelationsV2 };
|
package/dist/index.d.ts
CHANGED
|
@@ -182,6 +182,12 @@ interface Table {
|
|
|
182
182
|
indexes: Index[];
|
|
183
183
|
checks?: Check[];
|
|
184
184
|
foreignKeys?: ForeignKey[];
|
|
185
|
+
/**
|
|
186
|
+
* Set when the relation refuses writes, which today means a materialized view. Insert and
|
|
187
|
+
* update schemas are not emitted for one, because the database will always refuse the
|
|
188
|
+
* operation they describe.
|
|
189
|
+
*/
|
|
190
|
+
readOnly?: boolean;
|
|
185
191
|
meta?: Record<string, unknown>;
|
|
186
192
|
}
|
|
187
193
|
interface Enum {
|
|
@@ -223,6 +229,18 @@ declare function describeV1Column(column: any): Partial<Column> | null;
|
|
|
223
229
|
* `relations` record whose entries carry a `relationType`. That is specific enough not to
|
|
224
230
|
* collide with a table or an enum, both of which are checked before this.
|
|
225
231
|
*/
|
|
232
|
+
/**
|
|
233
|
+
* Whether a relation refuses writes outright.
|
|
234
|
+
*
|
|
235
|
+
* A materialized view does: `INSERT INTO mv ...` fails with `cannot change materialized view`,
|
|
236
|
+
* verified against Postgres. An insert or update schema for one describes an operation the
|
|
237
|
+
* database will always refuse.
|
|
238
|
+
*
|
|
239
|
+
* An ordinary view is deliberately not included. Postgres accepts an INSERT into a simple
|
|
240
|
+
* auto-updatable view, and whether a given view qualifies depends on its query rather than on
|
|
241
|
+
* anything the schema file states, so refusing them all would take away something that works.
|
|
242
|
+
*/
|
|
243
|
+
declare function isReadOnlyRelation(val: any): boolean;
|
|
226
244
|
declare function isRelationsV2(val: any): boolean;
|
|
227
245
|
/**
|
|
228
246
|
* Read the relations declared by `defineRelations`.
|
|
@@ -338,4 +356,4 @@ declare class SchemaAnalyzer {
|
|
|
338
356
|
analyze(opts?: AnalyzeOptions): Promise<Analysis>;
|
|
339
357
|
}
|
|
340
358
|
|
|
341
|
-
export { type Analysis, type AnalyzeOptions, type Check, type Column, type ColumnRef, type ColumnShape, type Dialect, type Enum, type ForeignKey, type Index, type Issue, type Key, type Relation, SchemaAnalyzer, type Table, SchemaAnalyzer as default, describeV1Column, isRelationsV2, readRelationsV2 };
|
|
359
|
+
export { type Analysis, type AnalyzeOptions, type Check, type Column, type ColumnRef, type ColumnShape, type Dialect, type Enum, type ForeignKey, type Index, type Issue, type Key, type Relation, SchemaAnalyzer, type Table, SchemaAnalyzer as default, describeV1Column, isReadOnlyRelation, isRelationsV2, readRelationsV2 };
|
package/dist/index.js
CHANGED
|
@@ -189,6 +189,12 @@ function getSymbolOf(target, key) {
|
|
|
189
189
|
}
|
|
190
190
|
return target[Symbol.for(key)];
|
|
191
191
|
}
|
|
192
|
+
function isReadOnlyRelation(val) {
|
|
193
|
+
if (!val || typeof val !== "object") return false;
|
|
194
|
+
return Object.getOwnPropertySymbols(val).some(
|
|
195
|
+
(sym) => String(sym.description).includes("MaterializedViewConfig")
|
|
196
|
+
);
|
|
197
|
+
}
|
|
192
198
|
function isRelationsV2(val) {
|
|
193
199
|
if (!val || typeof val !== "object" || Array.isArray(val)) return false;
|
|
194
200
|
const entries = Object.values(val);
|
|
@@ -718,6 +724,9 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
718
724
|
indexes: [...pkCols.length ? [{ columns: pkCols }] : [], ...indexes],
|
|
719
725
|
checks,
|
|
720
726
|
foreignKeys,
|
|
727
|
+
// A materialized view refuses every write, so the generators skip its insert and update
|
|
728
|
+
// schemas rather than describe an operation the database will always reject.
|
|
729
|
+
...isReadOnlyRelation(tbl) ? { readOnly: true } : {},
|
|
721
730
|
meta: {}
|
|
722
731
|
};
|
|
723
732
|
}
|
|
@@ -918,6 +927,7 @@ export {
|
|
|
918
927
|
SchemaAnalyzer,
|
|
919
928
|
index_default as default,
|
|
920
929
|
describeV1Column,
|
|
930
|
+
isReadOnlyRelation,
|
|
921
931
|
isRelationsV2,
|
|
922
932
|
readRelationsV2
|
|
923
933
|
};
|