ormbridge 0.12.1 → 0.14.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/README.md +19 -4
- package/dist/cliRunner.js +19 -1
- package/dist/cliRunner.js.map +1 -1
- package/dist/config.d.ts +5 -0
- package/dist/config.js +17 -0
- package/dist/config.js.map +1 -1
- package/dist/emitters/jpa.d.ts +17 -2
- package/dist/emitters/jpa.js +55 -7
- package/dist/emitters/jpa.js.map +1 -1
- package/dist/emitters/jpaKeyClass.d.ts +18 -0
- package/dist/emitters/jpaKeyClass.js +88 -0
- package/dist/emitters/jpaKeyClass.js.map +1 -0
- package/dist/emitters/jpaKeys.d.ts +1 -7
- package/dist/emitters/jpaKeys.js +0 -43
- package/dist/emitters/jpaKeys.js.map +1 -1
- package/dist/emitters/jpaRelations.d.ts +5 -1
- package/dist/emitters/jpaRelations.js +7 -1
- package/dist/emitters/jpaRelations.js.map +1 -1
- package/dist/emitters/jpaRender.d.ts +5 -1
- package/dist/emitters/jpaRender.js +11 -4
- package/dist/emitters/jpaRender.js.map +1 -1
- package/dist/emitters/jpaTypes.d.ts +9 -3
- package/dist/emitters/jpaTypes.js +8 -0
- package/dist/emitters/jpaTypes.js.map +1 -1
- package/dist/emitters/neo4jEdges.d.ts +46 -0
- package/dist/emitters/neo4jEdges.js +147 -0
- package/dist/emitters/neo4jEdges.js.map +1 -0
- package/dist/emitters/neo4jGraph.d.ts +9 -0
- package/dist/emitters/neo4jGraph.js +9 -5
- package/dist/emitters/neo4jGraph.js.map +1 -1
- package/dist/emitters/neo4jRelationships.d.ts +3 -1
- package/dist/emitters/neo4jRelationships.js +1 -1
- package/dist/emitters/neo4jRelationships.js.map +1 -1
- package/dist/emitters/neomodel.d.ts +20 -0
- package/dist/emitters/neomodel.js +415 -0
- package/dist/emitters/neomodel.js.map +1 -0
- package/dist/emitters/neomodelNames.d.ts +25 -0
- package/dist/emitters/neomodelNames.js +159 -0
- package/dist/emitters/neomodelNames.js.map +1 -0
- package/dist/emitters/neomodelProperties.d.ts +48 -0
- package/dist/emitters/neomodelProperties.js +220 -0
- package/dist/emitters/neomodelProperties.js.map +1 -0
- package/dist/emitters/sdn.d.ts +27 -0
- package/dist/emitters/sdn.js +584 -0
- package/dist/emitters/sdn.js.map +1 -0
- package/dist/emitters/sdnTypes.d.ts +7 -0
- package/dist/emitters/sdnTypes.js +81 -0
- package/dist/emitters/sdnTypes.js.map +1 -0
- package/dist/formats.d.ts +11 -0
- package/dist/formats.js +48 -3
- package/dist/formats.js.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/io.js +62 -21
- package/dist/io.js.map +1 -1
- package/dist/parsers/jpaBuild.js +2 -1
- package/dist/parsers/jpaBuild.js.map +1 -1
- package/dist/parsers/jpaClasses.js +7 -1
- package/dist/parsers/jpaClasses.js.map +1 -1
- package/dist/parsers/jpaColumns.d.ts +4 -1
- package/dist/parsers/jpaColumns.js +8 -2
- package/dist/parsers/jpaColumns.js.map +1 -1
- package/dist/parsers/jpaEntities.js +15 -0
- package/dist/parsers/jpaEntities.js.map +1 -1
- package/dist/parsers/jpaModel.d.ts +6 -0
- package/dist/parsers/sqlDdl.js +1306 -65
- package/dist/parsers/sqlDdl.js.map +1 -1
- package/dist/parsers/sqlMigrationOrder.d.ts +8 -0
- package/dist/parsers/sqlMigrationOrder.js +110 -0
- package/dist/parsers/sqlMigrationOrder.js.map +1 -0
- package/dist/parsers/sqlSyntax.d.ts +6 -0
- package/dist/parsers/sqlSyntax.js +15 -2
- package/dist/parsers/sqlSyntax.js.map +1 -1
- package/dist/parsers/zod.d.ts +11 -0
- package/dist/parsers/zod.js +796 -0
- package/dist/parsers/zod.js.map +1 -0
- package/dist/parsers/zodFields.d.ts +73 -0
- package/dist/parsers/zodFields.js +681 -0
- package/dist/parsers/zodFields.js.map +1 -0
- package/dist/parsers/zodSyntax.d.ts +72 -0
- package/dist/parsers/zodSyntax.js +347 -0
- package/dist/parsers/zodSyntax.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { toSnakeCase } from '../naming.js';
|
|
2
|
+
/** Name and literal helpers of the neomodel writer. */
|
|
3
|
+
/** Python keywords: an identifier with one of these names does not parse. */
|
|
4
|
+
const PYTHON_KEYWORDS = new Set([
|
|
5
|
+
'False',
|
|
6
|
+
'None',
|
|
7
|
+
'True',
|
|
8
|
+
'and',
|
|
9
|
+
'as',
|
|
10
|
+
'assert',
|
|
11
|
+
'async',
|
|
12
|
+
'await',
|
|
13
|
+
'break',
|
|
14
|
+
'class',
|
|
15
|
+
'continue',
|
|
16
|
+
'def',
|
|
17
|
+
'del',
|
|
18
|
+
'elif',
|
|
19
|
+
'else',
|
|
20
|
+
'except',
|
|
21
|
+
'finally',
|
|
22
|
+
'for',
|
|
23
|
+
'from',
|
|
24
|
+
'global',
|
|
25
|
+
'if',
|
|
26
|
+
'import',
|
|
27
|
+
'in',
|
|
28
|
+
'is',
|
|
29
|
+
'lambda',
|
|
30
|
+
'nonlocal',
|
|
31
|
+
'not',
|
|
32
|
+
'or',
|
|
33
|
+
'pass',
|
|
34
|
+
'raise',
|
|
35
|
+
'return',
|
|
36
|
+
'try',
|
|
37
|
+
'while',
|
|
38
|
+
'with',
|
|
39
|
+
'yield',
|
|
40
|
+
]);
|
|
41
|
+
/**
|
|
42
|
+
* Attribute names that neomodel itself uses on a node or relationship class. A property with one of these
|
|
43
|
+
* names is refused (`id`, `element_id`, `deleted`, `source`, `target`) or hides a method (`save`, `delete`).
|
|
44
|
+
*/
|
|
45
|
+
export const RESERVED_ATTRIBUTES = new Set([
|
|
46
|
+
'DoesNotExist',
|
|
47
|
+
'bulk_save',
|
|
48
|
+
'create',
|
|
49
|
+
'create_or_update',
|
|
50
|
+
'cypher',
|
|
51
|
+
'defined_properties',
|
|
52
|
+
'deflate',
|
|
53
|
+
'delete',
|
|
54
|
+
'deleted',
|
|
55
|
+
'element_id',
|
|
56
|
+
'element_id_property',
|
|
57
|
+
'end_node',
|
|
58
|
+
'get_or_create',
|
|
59
|
+
'id',
|
|
60
|
+
'inflate',
|
|
61
|
+
'inherited_labels',
|
|
62
|
+
'inherited_optional_labels',
|
|
63
|
+
'labels',
|
|
64
|
+
'nodes',
|
|
65
|
+
'refresh',
|
|
66
|
+
'save',
|
|
67
|
+
'source',
|
|
68
|
+
'start_node',
|
|
69
|
+
'target',
|
|
70
|
+
'was_saved',
|
|
71
|
+
]);
|
|
72
|
+
/**
|
|
73
|
+
* Names the generated module imports or defines at the top level. A node class with one of these names
|
|
74
|
+
* would hide the import, so its class is renamed and the label is kept with `__label__`.
|
|
75
|
+
*/
|
|
76
|
+
export const RESERVED_TYPES = new Set([
|
|
77
|
+
'AliasProperty',
|
|
78
|
+
'ArrayProperty',
|
|
79
|
+
'BooleanProperty',
|
|
80
|
+
'DateProperty',
|
|
81
|
+
'DateTimeNeo4jFormatProperty',
|
|
82
|
+
'datetime',
|
|
83
|
+
'timezone',
|
|
84
|
+
'DateTimeProperty',
|
|
85
|
+
'EmailProperty',
|
|
86
|
+
'FloatProperty',
|
|
87
|
+
'FulltextIndex',
|
|
88
|
+
'IntegerProperty',
|
|
89
|
+
'JSONProperty',
|
|
90
|
+
'One',
|
|
91
|
+
'OneOrMore',
|
|
92
|
+
'Q',
|
|
93
|
+
'Relationship',
|
|
94
|
+
'RelationshipFrom',
|
|
95
|
+
'RelationshipTo',
|
|
96
|
+
'StringProperty',
|
|
97
|
+
'StructuredNode',
|
|
98
|
+
'StructuredRel',
|
|
99
|
+
'UniqueIdProperty',
|
|
100
|
+
'ZeroOrMore',
|
|
101
|
+
'ZeroOrOne',
|
|
102
|
+
'date',
|
|
103
|
+
'uuid4',
|
|
104
|
+
]);
|
|
105
|
+
const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
106
|
+
/** True when the text is a plain Python identifier that is not a keyword. */
|
|
107
|
+
export function isPythonIdentifier(text) {
|
|
108
|
+
return IDENTIFIER.test(text) && !PYTHON_KEYWORDS.has(text);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The Python attribute name for a graph property key or relation name: snake_case, a leading underscore
|
|
112
|
+
* before a digit, a trailing underscore when the word is a keyword or one neomodel uses (`id` is `id_`).
|
|
113
|
+
*/
|
|
114
|
+
export function attributeNameOf(raw) {
|
|
115
|
+
let name = toSnakeCase(raw);
|
|
116
|
+
if (name === '') {
|
|
117
|
+
name = 'value';
|
|
118
|
+
}
|
|
119
|
+
if (/^[0-9]/.test(name)) {
|
|
120
|
+
name = `_${name}`;
|
|
121
|
+
}
|
|
122
|
+
return PYTHON_KEYWORDS.has(name) || RESERVED_ATTRIBUTES.has(name)
|
|
123
|
+
? `${name}_`
|
|
124
|
+
: name;
|
|
125
|
+
}
|
|
126
|
+
/** Reserves `base` in `used`, appending `_2`, `_3`, ... when the name is taken. */
|
|
127
|
+
export function uniqueAttribute(base, used) {
|
|
128
|
+
let candidate = base;
|
|
129
|
+
let suffix = 2;
|
|
130
|
+
while (used.has(candidate)) {
|
|
131
|
+
candidate = `${base}_${suffix}`;
|
|
132
|
+
suffix += 1;
|
|
133
|
+
}
|
|
134
|
+
used.add(candidate);
|
|
135
|
+
return candidate;
|
|
136
|
+
}
|
|
137
|
+
/** Reserves a class name in `used`, appending 2, 3, ... when it is taken. */
|
|
138
|
+
export function uniqueClassName(base, used) {
|
|
139
|
+
let candidate = base;
|
|
140
|
+
let suffix = 2;
|
|
141
|
+
while (used.has(candidate)) {
|
|
142
|
+
candidate = `${base}${suffix}`;
|
|
143
|
+
suffix += 1;
|
|
144
|
+
}
|
|
145
|
+
used.add(candidate);
|
|
146
|
+
return candidate;
|
|
147
|
+
}
|
|
148
|
+
/** A class name for a node label: the label when it is a valid identifier, otherwise a repaired form. */
|
|
149
|
+
export function classNameOf(label) {
|
|
150
|
+
const cleaned = label.replace(/[^A-Za-z0-9_]/g, '_');
|
|
151
|
+
const prefixed = /^[0-9]/.test(cleaned) ? `_${cleaned}` : cleaned;
|
|
152
|
+
const named = prefixed === '' ? 'Node' : prefixed;
|
|
153
|
+
return PYTHON_KEYWORDS.has(named) ? `${named}_` : named;
|
|
154
|
+
}
|
|
155
|
+
/** A Python string literal in double quotes (the JSON escapes are valid Python escapes). */
|
|
156
|
+
export function pyString(value) {
|
|
157
|
+
return JSON.stringify(value);
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=neomodelNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neomodelNames.js","sourceRoot":"","sources":["../../src/emitters/neomodelNames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,uDAAuD;AAEvD,6EAA6E;AAC7E,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IACnD,OAAO;IACP,MAAM;IACN,MAAM;IACN,KAAK;IACL,IAAI;IACJ,QAAQ;IACR,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,UAAU;IACV,KAAK;IACL,KAAK;IACL,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,KAAK;IACL,MAAM;IACN,QAAQ;IACR,IAAI;IACJ,QAAQ;IACR,IAAI;IACJ,IAAI;IACJ,QAAQ;IACR,UAAU;IACV,KAAK;IACL,IAAI;IACJ,MAAM;IACN,OAAO;IACP,QAAQ;IACR,KAAK;IACL,OAAO;IACP,MAAM;IACN,OAAO;CACR,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC;IAC9D,cAAc;IACd,WAAW;IACX,QAAQ;IACR,kBAAkB;IAClB,QAAQ;IACR,oBAAoB;IACpB,SAAS;IACT,QAAQ;IACR,SAAS;IACT,YAAY;IACZ,qBAAqB;IACrB,UAAU;IACV,eAAe;IACf,IAAI;IACJ,SAAS;IACT,kBAAkB;IAClB,2BAA2B;IAC3B,QA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AM,UAAU,QAAQ,CAAC,KAAa;IACpC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { IrField, IrSchema } from '../ir.js';
|
|
2
|
+
import type { GraphProperty } from './neo4jGraph.js';
|
|
3
|
+
/** Turns one graph property into a neomodel property class call such as `StringProperty(required=True)`. */
|
|
4
|
+
/** The imports the generated module needs, collected while the classes are planned. */
|
|
5
|
+
export declare class ModuleImports {
|
|
6
|
+
/** Names imported from `neomodel`. */
|
|
7
|
+
readonly neomodel: Set<string>;
|
|
8
|
+
/** `from datetime import date` (the default of a date column). */
|
|
9
|
+
usesDate: boolean;
|
|
10
|
+
/** Names imported from `datetime` for the default of a date and time column. */
|
|
11
|
+
readonly datetime: Set<string>;
|
|
12
|
+
/** `from uuid import uuid4` (the default of a UUID column). */
|
|
13
|
+
usesUuid: boolean;
|
|
14
|
+
/** Records a name of `neomodel` and returns it. */
|
|
15
|
+
use(name: string): string;
|
|
16
|
+
}
|
|
17
|
+
/** Which indexes and constraints a property takes part in. */
|
|
18
|
+
export interface PropertyRole {
|
|
19
|
+
unique: boolean;
|
|
20
|
+
index: boolean;
|
|
21
|
+
fulltext: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** A property class and its arguments, ready to be laid out. */
|
|
24
|
+
export interface PropertyCall {
|
|
25
|
+
className: string;
|
|
26
|
+
args: string[];
|
|
27
|
+
}
|
|
28
|
+
export interface PropertyContext {
|
|
29
|
+
schema: IrSchema;
|
|
30
|
+
imports: ModuleImports;
|
|
31
|
+
warnings: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface PropertyInput {
|
|
34
|
+
/** `Model.field`, for warnings. */
|
|
35
|
+
label: string;
|
|
36
|
+
property: GraphProperty;
|
|
37
|
+
/** The IR field behind the property; undefined for a foreign key column. */
|
|
38
|
+
field: IrField | undefined;
|
|
39
|
+
role: PropertyRole;
|
|
40
|
+
/** The attribute name in the class; `db_property` is written when it differs from the key. */
|
|
41
|
+
attribute: string;
|
|
42
|
+
/** True for the single UUID key of a node, which `UniqueIdProperty` can generate. */
|
|
43
|
+
uniqueId: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** The text of a call, `Name(arg, arg)`. */
|
|
46
|
+
export declare function callText(call: PropertyCall): string;
|
|
47
|
+
/** Plans the property class and arguments of one graph property. */
|
|
48
|
+
export declare function planProperty(context: PropertyContext, input: PropertyInput): PropertyCall;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { oneLine } from './neo4jNames.js';
|
|
2
|
+
import { mapFieldType } from './neo4jTypes.js';
|
|
3
|
+
import { pyString } from './neomodelNames.js';
|
|
4
|
+
/** Turns one graph property into a neomodel property class call such as `StringProperty(required=True)`. */
|
|
5
|
+
/** The imports the generated module needs, collected while the classes are planned. */
|
|
6
|
+
export class ModuleImports {
|
|
7
|
+
/** Names imported from `neomodel`. */
|
|
8
|
+
neomodel = new Set();
|
|
9
|
+
/** `from datetime import date` (the default of a date column). */
|
|
10
|
+
usesDate = false;
|
|
11
|
+
/** Names imported from `datetime` for the default of a date and time column. */
|
|
12
|
+
datetime = new Set();
|
|
13
|
+
/** `from uuid import uuid4` (the default of a UUID column). */
|
|
14
|
+
usesUuid = false;
|
|
15
|
+
/** Records a name of `neomodel` and returns it. */
|
|
16
|
+
use(name) {
|
|
17
|
+
this.neomodel.add(name);
|
|
18
|
+
return name;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** The property class for a Neo4j type, plus the note about what neomodel stores instead. */
|
|
22
|
+
function classFor(type, context, label) {
|
|
23
|
+
const { imports } = context;
|
|
24
|
+
switch (type.name) {
|
|
25
|
+
case 'INTEGER':
|
|
26
|
+
return imports.use('IntegerProperty');
|
|
27
|
+
case 'FLOAT':
|
|
28
|
+
return imports.use('FloatProperty');
|
|
29
|
+
case 'BOOLEAN':
|
|
30
|
+
return imports.use('BooleanProperty');
|
|
31
|
+
case 'DATE':
|
|
32
|
+
return imports.use('DateProperty');
|
|
33
|
+
case 'ZONED DATETIME':
|
|
34
|
+
case 'LOCAL DATETIME':
|
|
35
|
+
return imports.use('DateTimeNeo4jFormatProperty');
|
|
36
|
+
case 'LOCAL TIME':
|
|
37
|
+
case 'ZONED TIME':
|
|
38
|
+
context.warnings.push(`${label}: neomodel has no time property; the value is stored as an ISO 8601 text in a StringProperty.`);
|
|
39
|
+
return imports.use('StringProperty');
|
|
40
|
+
case 'DURATION':
|
|
41
|
+
context.warnings.push(`${label}: neomodel has no duration property; the value is stored as an ISO 8601 text in a StringProperty.`);
|
|
42
|
+
return imports.use('StringProperty');
|
|
43
|
+
case 'BYTE ARRAY':
|
|
44
|
+
context.warnings.push(`${label}: neomodel has no binary property; the value is stored as base64 text in a StringProperty.`);
|
|
45
|
+
return imports.use('StringProperty');
|
|
46
|
+
default:
|
|
47
|
+
return imports.use('StringProperty');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function enumOf(field, schema) {
|
|
51
|
+
return field.enumName === undefined
|
|
52
|
+
? undefined
|
|
53
|
+
: schema.enums.find((candidate) => candidate.name === field.enumName);
|
|
54
|
+
}
|
|
55
|
+
/** `{"draft": "DRAFT", ...}`: the stored value and the name of the member. */
|
|
56
|
+
function choices(definition) {
|
|
57
|
+
const items = definition.values.map((value) => `${pyString(value.dbValue)}: ${pyString(value.name)}`);
|
|
58
|
+
return `{${items.join(', ')}}`;
|
|
59
|
+
}
|
|
60
|
+
/** The text of a call, `Name(arg, arg)`. */
|
|
61
|
+
export function callText(call) {
|
|
62
|
+
return `${call.className}(${call.args.join(', ')})`;
|
|
63
|
+
}
|
|
64
|
+
/** The base property of a field (the element property for an array). */
|
|
65
|
+
function baseCall(context, label, field, type) {
|
|
66
|
+
if (field !== undefined && field.type === 'json') {
|
|
67
|
+
return { className: context.imports.use('JSONProperty'), args: [] };
|
|
68
|
+
}
|
|
69
|
+
const className = classFor(type, context, label);
|
|
70
|
+
const args = [];
|
|
71
|
+
if (className === 'StringProperty' && field !== undefined) {
|
|
72
|
+
const definition = enumOf(field, context.schema);
|
|
73
|
+
if (definition !== undefined && type.name === 'STRING') {
|
|
74
|
+
args.push(`choices=${choices(definition)}`);
|
|
75
|
+
}
|
|
76
|
+
else if (field.maxLength !== undefined && field.type === 'string') {
|
|
77
|
+
args.push(`max_length=${field.maxLength}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (field !== undefined &&
|
|
81
|
+
enumOf(field, context.schema) !== undefined &&
|
|
82
|
+
type.name !== 'STRING') {
|
|
83
|
+
context.warnings.push(`${label}: neomodel cannot restrict ${className} to the values of enum ${field.enumName ?? ''}; the values are not checked.`);
|
|
84
|
+
}
|
|
85
|
+
return { className, args };
|
|
86
|
+
}
|
|
87
|
+
/** The Python text of a default, or undefined (with a warning) when neomodel cannot hold it. */
|
|
88
|
+
function defaultArgs(context, label, field, base, isArray) {
|
|
89
|
+
const value = field.default ??
|
|
90
|
+
// A timestamp refreshed on every save starts as the time of the first save.
|
|
91
|
+
(field.isAutoUpdated &&
|
|
92
|
+
(base.className === 'DateTimeNeo4jFormatProperty' ||
|
|
93
|
+
base.className === 'DateProperty')
|
|
94
|
+
? { kind: 'now' }
|
|
95
|
+
: undefined);
|
|
96
|
+
if (value === undefined || value.kind === 'autoIncrement') {
|
|
97
|
+
if (value !== undefined) {
|
|
98
|
+
context.warnings.push(`${label}: auto-increment has no neomodel equivalent; supply the value yourself (a UUID key with UniqueIdProperty needs none).`);
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
const drop = (what) => {
|
|
103
|
+
context.warnings.push(`${label}: ${what} has no neomodel equivalent and was dropped; set the value when you create the node.`);
|
|
104
|
+
return undefined;
|
|
105
|
+
};
|
|
106
|
+
if (isArray) {
|
|
107
|
+
return drop('the default of an array');
|
|
108
|
+
}
|
|
109
|
+
switch (value.kind) {
|
|
110
|
+
case 'literal':
|
|
111
|
+
return literalArgs(value.value, base.className, drop);
|
|
112
|
+
case 'now':
|
|
113
|
+
if (base.className === 'DateTimeNeo4jFormatProperty') {
|
|
114
|
+
// DateTimeNeo4jFormatProperty(default_now=True) would fix the time when the module is imported.
|
|
115
|
+
if (mapFieldType(field).type.name === 'LOCAL DATETIME') {
|
|
116
|
+
context.imports.datetime.add('datetime');
|
|
117
|
+
return ['default=datetime.now'];
|
|
118
|
+
}
|
|
119
|
+
context.imports.datetime.add('datetime').add('timezone');
|
|
120
|
+
return ['default=lambda: datetime.now(timezone.utc)'];
|
|
121
|
+
}
|
|
122
|
+
if (base.className === 'DateProperty') {
|
|
123
|
+
context.imports.usesDate = true;
|
|
124
|
+
return ['default=date.today'];
|
|
125
|
+
}
|
|
126
|
+
return drop('the default of the current time');
|
|
127
|
+
case 'uuid':
|
|
128
|
+
if (base.className === 'StringProperty') {
|
|
129
|
+
context.imports.usesUuid = true;
|
|
130
|
+
return ['default=lambda: str(uuid4())'];
|
|
131
|
+
}
|
|
132
|
+
return drop('the default of a generated UUID');
|
|
133
|
+
case 'enumValue': {
|
|
134
|
+
const definition = enumOf(field, context.schema);
|
|
135
|
+
const member = definition?.values.find((candidate) => candidate.name === value.value);
|
|
136
|
+
return base.className === 'StringProperty'
|
|
137
|
+
? [`default=${pyString(member?.dbValue ?? value.value)}`]
|
|
138
|
+
: drop(`the default "${value.value}"`);
|
|
139
|
+
}
|
|
140
|
+
case 'clientGenerated':
|
|
141
|
+
return drop(`the ${value.generator}() default`);
|
|
142
|
+
case 'dbExpression':
|
|
143
|
+
return drop(`the database default ${oneLine(value.expression)}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function literalArgs(value, className, drop) {
|
|
147
|
+
const fits = (className === 'StringProperty' && typeof value !== 'boolean') ||
|
|
148
|
+
(className === 'IntegerProperty' &&
|
|
149
|
+
typeof value === 'number' &&
|
|
150
|
+
Number.isInteger(value)) ||
|
|
151
|
+
(className === 'FloatProperty' &&
|
|
152
|
+
typeof value === 'number' &&
|
|
153
|
+
Number.isFinite(value)) ||
|
|
154
|
+
(className === 'BooleanProperty' && typeof value === 'boolean');
|
|
155
|
+
if (!fits) {
|
|
156
|
+
return drop(`the default ${JSON.stringify(value)}`);
|
|
157
|
+
}
|
|
158
|
+
if (typeof value === 'boolean') {
|
|
159
|
+
return [`default=${value ? 'True' : 'False'}`];
|
|
160
|
+
}
|
|
161
|
+
if (className === 'StringProperty') {
|
|
162
|
+
return [`default=${pyString(String(value))}`];
|
|
163
|
+
}
|
|
164
|
+
const text = String(value);
|
|
165
|
+
return [
|
|
166
|
+
`default=${className === 'FloatProperty' && /^-?\d+$/.test(text) ? `${text}.0` : text}`,
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
/** Plans the property class and arguments of one graph property. */
|
|
170
|
+
export function planProperty(context, input) {
|
|
171
|
+
const { label, property, field, role, attribute } = input;
|
|
172
|
+
const dbProperty = attribute === property.key ? [] : [`db_property=${pyString(property.key)}`];
|
|
173
|
+
if (input.uniqueId) {
|
|
174
|
+
return {
|
|
175
|
+
className: context.imports.use('UniqueIdProperty'),
|
|
176
|
+
args: dbProperty,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const isArray = property.type.name.startsWith('LIST<');
|
|
180
|
+
let call;
|
|
181
|
+
if (isArray && field !== undefined) {
|
|
182
|
+
const element = mapFieldType({
|
|
183
|
+
...field,
|
|
184
|
+
arrayDepth: undefined,
|
|
185
|
+
}).type;
|
|
186
|
+
const base = baseCall(context, label, field, element);
|
|
187
|
+
call = {
|
|
188
|
+
className: context.imports.use('ArrayProperty'),
|
|
189
|
+
args: [callText(base)],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
call = baseCall(context, label, field, property.type);
|
|
194
|
+
}
|
|
195
|
+
const flags = [];
|
|
196
|
+
if (role.unique) {
|
|
197
|
+
flags.push('unique_index=True');
|
|
198
|
+
}
|
|
199
|
+
else if (role.index) {
|
|
200
|
+
flags.push('index=True');
|
|
201
|
+
}
|
|
202
|
+
if (role.fulltext) {
|
|
203
|
+
if (call.className === 'StringProperty') {
|
|
204
|
+
flags.push(`fulltext_index=${context.imports.use('FulltextIndex')}()`);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
context.warnings.push(`${label}: a full-text index needs a string property, so it was dropped.`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const defaults = field === undefined
|
|
211
|
+
? []
|
|
212
|
+
: (defaultArgs(context, label, field, call, isArray) ?? []);
|
|
213
|
+
const hasDefault = defaults.length > 0;
|
|
214
|
+
const required = property.required && !hasDefault ? ['required=True'] : [];
|
|
215
|
+
return {
|
|
216
|
+
className: call.className,
|
|
217
|
+
args: [...call.args, ...flags, ...required, ...defaults, ...dbProperty],
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=neomodelProperties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neomodelProperties.js","sourceRoot":"","sources":["../../src/emitters/neomodelProperties.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAkB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,4GAA4G;AAE5G,uFAAuF;AACvF,MAAM,OAAO,aAAa;IACxB,sCAAsC;IAC7B,QAAQ,GAAgB,IAAI,GAAG,EAAU,CAAC;IACnD,kEAAkE;IAClE,QAAQ,GAAY,KAAK,CAAC;IAC1B,gFAAgF;IACvE,QAAQ,GAAgB,IAAI,GAAG,EAAU,CAAC;IACnD,+DAA+D;IAC/D,QAAQ,GAAY,KAAK,CAAC;IAE1B,mDAAmD;IACnD,GAAG,CAAC,IAAY;QACd,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAk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AC,CAAC,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAChE,MAAM,UAAU,GAAY,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAChD,MAAM,QAAQ,GACZ,QAAQ,CAAC,QAAQ,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,OAAO;QACL,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,GAAG,KAAK,EAAE,GAAG,QAAQ,EAAE,GAAG,QAAQ,EAAE,GAAG,UAAU,CAAC;KACxE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MultiFileEmitOutput } from '../formats.js';
|
|
2
|
+
import type { IrSchema } from '../ir.js';
|
|
3
|
+
/**
|
|
4
|
+
* Spring Data Neo4j writer (Java, SDN 7 with Spring Boot 3).
|
|
5
|
+
*
|
|
6
|
+
* Writes one `@Node("Label")` class per node label, a Java `enum` per enum (with a
|
|
7
|
+
* `Neo4jPersistentPropertyConverter` when the stored values differ from the constant names), and a
|
|
8
|
+
* `@RelationshipProperties` class for every direction of a join table that has extra columns. Properties
|
|
9
|
+
* whose graph key differs from the Java name carry `@Property`. Relationships are `@Relationship` fields with
|
|
10
|
+
* the type and the direction, a single value or a `List`. Labels and relationship types are the ones of the
|
|
11
|
+
* Cypher writer, so the three Neo4j outputs agree. Foreign key columns stay as plain properties.
|
|
12
|
+
*
|
|
13
|
+
* The identifier follows the source key: a generated integer is Neo4j's internal id (`@GeneratedValue`), a
|
|
14
|
+
* generated UUID a `UUIDStringGenerator` string, any other single column an assigned `@Id`; a composite or
|
|
15
|
+
* missing key becomes a generated internal id `graphId` and the key columns are plain properties.
|
|
16
|
+
*/
|
|
17
|
+
export { isValidJavaPackage } from './jpaNames.js';
|
|
18
|
+
export declare const DEFAULT_SDN_PACKAGE: string;
|
|
19
|
+
export interface SdnEmitOptions {
|
|
20
|
+
/** Use camelCase graph property keys (the `normalize` naming mode); otherwise the column names are kept. */
|
|
21
|
+
camelFields: boolean;
|
|
22
|
+
/** Java package of the generated classes; defaults to `app.models`. */
|
|
23
|
+
packageName?: string;
|
|
24
|
+
/** Write the `// <auto-generated>` comment at the top of every file (default true). */
|
|
25
|
+
header?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare function emitSdn(schema: IrSchema, options: SdnEmitOptions): MultiFileEmitOutput;
|