supa-forge 0.1.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/README.md +65 -0
- package/bin/cli.js +116 -0
- package/dist/index.d.ts +210 -0
- package/dist/index.js +79 -0
- package/dist/index.mjs +1364 -0
- package/dist/typeorm.d.ts +26 -0
- package/dist/typeorm.js +1 -0
- package/dist/typeorm.mjs +15 -0
- package/examples/Only CLS/package-lock.json +3140 -0
- package/examples/Only CLS/package.json +25 -0
- package/examples/Only CLS/src/employee.test.ts +109 -0
- package/examples/Only CLS/src/entities/Employee.entity.ts +27 -0
- package/examples/Only CLS/src/index.ts +45 -0
- package/examples/Only CLS/tsconfig.json +17 -0
- package/examples/Only CLS/vite.config.ts +8 -0
- package/examples/Only RLS/package-lock.json +3140 -0
- package/examples/Only RLS/package.json +25 -0
- package/examples/Only RLS/src/entities/Note.entity.ts +40 -0
- package/examples/Only RLS/src/entities/User.entity.ts +29 -0
- package/examples/Only RLS/src/index.ts +51 -0
- package/examples/Only RLS/src/notes.test.ts +123 -0
- package/examples/Only RLS/tsconfig.json +17 -0
- package/examples/Only RLS/vite.config.ts +8 -0
- package/examples/RBAC + CLS + RLS/package-lock.json +3140 -0
- package/examples/RBAC + CLS + RLS/package.json +21 -0
- package/examples/RBAC + CLS + RLS/src/entities/Project.entity.ts +47 -0
- package/examples/RBAC + CLS + RLS/src/entities/User.entity.ts +31 -0
- package/examples/RBAC + CLS + RLS/src/entities/UserRole.entity.ts +110 -0
- package/examples/RBAC + CLS + RLS/src/index.ts +42 -0
- package/examples/RBAC + CLS + RLS/src/project.test.ts +117 -0
- package/examples/RBAC + CLS + RLS/tsconfig.json +17 -0
- package/examples/RBAC + CLS + RLS/vite.config.ts +8 -0
- package/examples/Without Security/package-lock.json +3940 -0
- package/examples/Without Security/package.json +25 -0
- package/examples/Without Security/src/entities/Pharmacy.entity.ts +20 -0
- package/examples/Without Security/src/index.ts +52 -0
- package/examples/Without Security/src/pharmacy.test.ts +104 -0
- package/examples/Without Security/tsconfig.json +17 -0
- package/examples/Without Security/vite.config.ts +8 -0
- package/package.json +72 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1364 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import y from "chalk";
|
|
3
|
+
import { DataSource as pe } from "typeorm";
|
|
4
|
+
import { Client as $e } from "pg";
|
|
5
|
+
import * as g from "fs";
|
|
6
|
+
import * as C from "path";
|
|
7
|
+
import { z as I } from "zod";
|
|
8
|
+
const w = {
|
|
9
|
+
security: Symbol("supaforge:security"),
|
|
10
|
+
rls: Symbol("supaforge:rls"),
|
|
11
|
+
cls: Symbol("supaforge:cls"),
|
|
12
|
+
runSql: Symbol("supaforge:runsql")
|
|
13
|
+
};
|
|
14
|
+
function me(e) {
|
|
15
|
+
const r = e.toLowerCase().trim().split(""), n = ["c", "r", "u", "d"], i = r.filter((a) => !n.includes(a));
|
|
16
|
+
if (i.length > 0)
|
|
17
|
+
throw new Error(`Invalid permissions: ${i.join(", ")}. Expected only ${n.join(", ")}.`);
|
|
18
|
+
const t = [...new Set(r)].sort((a, o) => n.indexOf(a) - n.indexOf(o));
|
|
19
|
+
return t.includes("u") && !t.includes("r") && console.warn(y.yellow("Security Audit: 'u' permission found without 'r' on a security rule. In PostgreSQL, updates generally require select permissions on the columns used in the WHERE clause. If this is intentional (e.g., blinded updates), ensure your RLS/CLS allows it.")), t;
|
|
20
|
+
}
|
|
21
|
+
function Qn() {
|
|
22
|
+
return (e) => {
|
|
23
|
+
Reflect.defineMetadata(w.security, !0, e);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function Wn(e) {
|
|
27
|
+
return (r, n) => {
|
|
28
|
+
const i = me(e), t = typeof r == "function" ? r : r.constructor, a = Reflect.getMetadata(w.rls, t) ?? [];
|
|
29
|
+
a.push({
|
|
30
|
+
name: String(n),
|
|
31
|
+
crud: i,
|
|
32
|
+
definition: r[n]
|
|
33
|
+
}), Reflect.defineMetadata(w.rls, a, t);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function Vn(e) {
|
|
37
|
+
return (r, n) => {
|
|
38
|
+
const t = (Array.isArray(e) ? e : [e]).flatMap(
|
|
39
|
+
(l) => Object.entries(l).map(([s, u]) => ({
|
|
40
|
+
role: s,
|
|
41
|
+
permissions: me(u)
|
|
42
|
+
}))
|
|
43
|
+
), a = r.constructor, o = Reflect.getMetadata(w.cls, a) ?? [];
|
|
44
|
+
o.push({
|
|
45
|
+
propertyKey: String(n),
|
|
46
|
+
databaseName: "",
|
|
47
|
+
// Dynamically mapped via TypeORM introspection later
|
|
48
|
+
rules: t
|
|
49
|
+
}), Reflect.defineMetadata(w.cls, o, a);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function zn() {
|
|
53
|
+
return (e, r) => {
|
|
54
|
+
const n = typeof e == "function" ? e : e.constructor, i = Reflect.getMetadata(w.runSql, n) ?? [];
|
|
55
|
+
i.push({
|
|
56
|
+
name: String(r),
|
|
57
|
+
definition: e[r]
|
|
58
|
+
}), Reflect.defineMetadata(w.runSql, i, n);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const _ = {
|
|
62
|
+
isSecurityEnabled(e) {
|
|
63
|
+
return Reflect.getMetadata(w.security, e) === !0;
|
|
64
|
+
},
|
|
65
|
+
getRLS(e) {
|
|
66
|
+
return Reflect.getMetadata(w.rls, e) ?? [];
|
|
67
|
+
},
|
|
68
|
+
getCLS(e) {
|
|
69
|
+
return Reflect.getMetadata(w.cls, e) ?? [];
|
|
70
|
+
},
|
|
71
|
+
getCustomSql(e) {
|
|
72
|
+
return Reflect.getMetadata(w.runSql, e) ?? [];
|
|
73
|
+
}
|
|
74
|
+
}, Q = [
|
|
75
|
+
"anon",
|
|
76
|
+
"authenticated",
|
|
77
|
+
"service_role",
|
|
78
|
+
"postgres",
|
|
79
|
+
"supabase_admin",
|
|
80
|
+
"authenticator"
|
|
81
|
+
], De = `
|
|
82
|
+
CREATE OR REPLACE FUNCTION supaforge_create_role(target_role_name text)
|
|
83
|
+
RETURNS void
|
|
84
|
+
LANGUAGE plpgsql
|
|
85
|
+
AS $$
|
|
86
|
+
BEGIN
|
|
87
|
+
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = target_role_name) THEN
|
|
88
|
+
EXECUTE format('CREATE ROLE %I', target_role_name);
|
|
89
|
+
END IF;
|
|
90
|
+
|
|
91
|
+
EXECUTE format('GRANT %I TO postgres', target_role_name);
|
|
92
|
+
|
|
93
|
+
IF EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'authenticated') THEN
|
|
94
|
+
EXECUTE format('REVOKE authenticated FROM %I', target_role_name);
|
|
95
|
+
END IF;
|
|
96
|
+
|
|
97
|
+
IF EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'authenticator') THEN
|
|
98
|
+
EXECUTE format('GRANT %I TO authenticator', target_role_name);
|
|
99
|
+
END IF;
|
|
100
|
+
|
|
101
|
+
EXECUTE format('GRANT USAGE ON SCHEMA public TO %I', target_role_name);
|
|
102
|
+
EXECUTE format('GRANT USAGE ON ALL SEQUENCES IN SCHEMA public TO %I', target_role_name);
|
|
103
|
+
END;
|
|
104
|
+
$$;
|
|
105
|
+
`.trim(), de = {
|
|
106
|
+
c: "INSERT",
|
|
107
|
+
r: "SELECT",
|
|
108
|
+
u: "UPDATE",
|
|
109
|
+
d: "DELETE"
|
|
110
|
+
}, F = (e) => `"${e.replace(/"/g, '""')}"`, L = (e) => `'${e.replace(/'/g, "''")}'`;
|
|
111
|
+
function k(e) {
|
|
112
|
+
return Q.includes(e.toLowerCase());
|
|
113
|
+
}
|
|
114
|
+
function Me(e) {
|
|
115
|
+
const r = [], n = `public.${F(e.tableName)}`, i = {};
|
|
116
|
+
for (const t of e.columns)
|
|
117
|
+
for (const a of t.rules) {
|
|
118
|
+
const o = a.role;
|
|
119
|
+
Object.prototype.hasOwnProperty.call(i, o) || (i[o] = { c: /* @__PURE__ */ new Set(), r: /* @__PURE__ */ new Set(), u: /* @__PURE__ */ new Set(), d: /* @__PURE__ */ new Set() });
|
|
120
|
+
for (const l of a.permissions)
|
|
121
|
+
i[o][l].add(t.databaseName);
|
|
122
|
+
}
|
|
123
|
+
for (const [t, a] of Object.entries(i)) {
|
|
124
|
+
const o = F(t);
|
|
125
|
+
for (const [l, s] of Object.entries(a)) {
|
|
126
|
+
if (s.size === 0) continue;
|
|
127
|
+
const u = de[l];
|
|
128
|
+
if (l === "d")
|
|
129
|
+
r.push(`GRANT DELETE ON ${n} TO ${o};`);
|
|
130
|
+
else {
|
|
131
|
+
const f = Array.from(s).map(F).join(", ");
|
|
132
|
+
r.push(`GRANT ${u} (${f}) ON ${n} TO ${o};`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return r;
|
|
137
|
+
}
|
|
138
|
+
function ke(e) {
|
|
139
|
+
const r = [], n = `public.${F(e.tableName)}`;
|
|
140
|
+
for (const i of e.policies) {
|
|
141
|
+
const { role: t, expression: a } = i.definition(), o = Array.isArray(t) ? t : [t], l = o.map(F).join(", "), s = Array.isArray(t) ? t.join("_") : t;
|
|
142
|
+
for (const u of i.crud) {
|
|
143
|
+
const f = de[u], p = F(`supaforge_${e.tableName}_${s}_${u}_${i.name}`);
|
|
144
|
+
r.push(`DROP POLICY IF EXISTS ${p} ON ${n};`);
|
|
145
|
+
const c = `CREATE POLICY ${p} ON ${n} FOR ${f} TO ${l}`;
|
|
146
|
+
let d = `(${a})`;
|
|
147
|
+
if (o.some((h) => !k(h))) {
|
|
148
|
+
const h = o.filter((A) => !k(A)).map((A) => `(pg_has_role(current_user, ${L(A)}, 'MEMBER') AND (coalesce(auth.jwt() ->> 'user_role', 'none') = ${L(A)} OR (auth.jwt() -> 'user_roles') ? ${L(A)}))`);
|
|
149
|
+
d = `((${[...o.filter((A) => k(A)).map((A) => `pg_has_role(current_user, ${L(A)}, 'MEMBER')`), ...h].join(" OR ")}) AND ${d})`;
|
|
150
|
+
}
|
|
151
|
+
u === "c" ? r.push(`${c} WITH CHECK (${d});`) : u === "u" ? r.push(`${c} USING (${d}) WITH CHECK (${d});`) : r.push(`${c} USING (${d});`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return r;
|
|
155
|
+
}
|
|
156
|
+
function ye(e, r = {}) {
|
|
157
|
+
const { cls: n = !0, rls: i = !0 } = r, t = [];
|
|
158
|
+
t.push("-- Supaforge Security Migration"), t.push(""), t.push(De), t.push("");
|
|
159
|
+
const a = /* @__PURE__ */ new Set();
|
|
160
|
+
for (const o of e) {
|
|
161
|
+
for (const l of o.columns)
|
|
162
|
+
for (const s of l.rules)
|
|
163
|
+
k(s.role) || a.add(s.role);
|
|
164
|
+
for (const l of o.policies) {
|
|
165
|
+
const { role: s } = l.definition();
|
|
166
|
+
Array.isArray(s) ? s.forEach((u) => {
|
|
167
|
+
k(u) || a.add(u);
|
|
168
|
+
}) : k(s) || a.add(s);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (a.size > 0) {
|
|
172
|
+
t.push("-- Create custom security roles");
|
|
173
|
+
for (const o of a)
|
|
174
|
+
t.push(`SELECT supaforge_create_role(${L(o)});`);
|
|
175
|
+
t.push("");
|
|
176
|
+
}
|
|
177
|
+
for (const o of e) {
|
|
178
|
+
t.push(`-- Table: ${o.tableName}`);
|
|
179
|
+
const l = `public.${F(o.tableName)}`;
|
|
180
|
+
i && o.isSecurityEnabled ? t.push(`ALTER TABLE ${l} ENABLE ROW LEVEL SECURITY;`) : i || t.push(`ALTER TABLE ${l} DISABLE ROW LEVEL SECURITY;`), n && t.push(`REVOKE ALL ON TABLE ${l} FROM anon, authenticated, public;`), t.push(`
|
|
181
|
+
DO $$ DECLARE pol RECORD;
|
|
182
|
+
BEGIN
|
|
183
|
+
FOR pol IN (
|
|
184
|
+
SELECT policyname FROM pg_policies
|
|
185
|
+
WHERE schemaname = 'public'
|
|
186
|
+
AND tablename = ${L(o.tableName)}
|
|
187
|
+
AND policyname LIKE 'supaforge_%'
|
|
188
|
+
) LOOP
|
|
189
|
+
EXECUTE format('DROP POLICY IF EXISTS %I ON %s', pol.policyname, ${L(l)});
|
|
190
|
+
END LOOP;
|
|
191
|
+
END $$;`.trim()), n && t.push(...Me(o)), i && t.push(...ke(o));
|
|
192
|
+
for (const s of o.customSql)
|
|
193
|
+
t.push(`-- Custom SQL: ${s.name}`), t.push(s.definition());
|
|
194
|
+
t.push("");
|
|
195
|
+
}
|
|
196
|
+
return t.join(`
|
|
197
|
+
`);
|
|
198
|
+
}
|
|
199
|
+
function ge(e, r, n = "-- Revert logic generally requires manual review") {
|
|
200
|
+
return [
|
|
201
|
+
'import { MigrationInterface, QueryRunner } from "typeorm";',
|
|
202
|
+
"",
|
|
203
|
+
`export class ${e} implements MigrationInterface {`,
|
|
204
|
+
` name = '${e}'`,
|
|
205
|
+
"",
|
|
206
|
+
" public async up(queryRunner: QueryRunner): Promise<void> {",
|
|
207
|
+
" await queryRunner.query(`",
|
|
208
|
+
r.replace(/`/g, "\\\\`"),
|
|
209
|
+
" `);",
|
|
210
|
+
" }",
|
|
211
|
+
"",
|
|
212
|
+
" public async down(queryRunner: QueryRunner): Promise<void> {",
|
|
213
|
+
" await queryRunner.query(`",
|
|
214
|
+
n.replace(/`/g, "\\\\`"),
|
|
215
|
+
" `);",
|
|
216
|
+
" }",
|
|
217
|
+
"}"
|
|
218
|
+
].join(`
|
|
219
|
+
`);
|
|
220
|
+
}
|
|
221
|
+
/*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT */
|
|
222
|
+
function he(e) {
|
|
223
|
+
return typeof e > "u" || e === null;
|
|
224
|
+
}
|
|
225
|
+
function Pe(e) {
|
|
226
|
+
return typeof e == "object" && e !== null;
|
|
227
|
+
}
|
|
228
|
+
function Ue(e) {
|
|
229
|
+
return Array.isArray(e) ? e : he(e) ? [] : [e];
|
|
230
|
+
}
|
|
231
|
+
function Ye(e, r) {
|
|
232
|
+
var n, i, t, a;
|
|
233
|
+
if (r)
|
|
234
|
+
for (a = Object.keys(r), n = 0, i = a.length; n < i; n += 1)
|
|
235
|
+
t = a[n], e[t] = r[t];
|
|
236
|
+
return e;
|
|
237
|
+
}
|
|
238
|
+
function qe(e, r) {
|
|
239
|
+
var n = "", i;
|
|
240
|
+
for (i = 0; i < r; i += 1)
|
|
241
|
+
n += e;
|
|
242
|
+
return n;
|
|
243
|
+
}
|
|
244
|
+
function je(e) {
|
|
245
|
+
return e === 0 && Number.NEGATIVE_INFINITY === 1 / e;
|
|
246
|
+
}
|
|
247
|
+
var He = he, Be = Pe, Ke = Ue, Ge = qe, Qe = je, We = Ye, $ = {
|
|
248
|
+
isNothing: He,
|
|
249
|
+
isObject: Be,
|
|
250
|
+
toArray: Ke,
|
|
251
|
+
repeat: Ge,
|
|
252
|
+
isNegativeZero: Qe,
|
|
253
|
+
extend: We
|
|
254
|
+
};
|
|
255
|
+
function Ee(e, r) {
|
|
256
|
+
var n = "", i = e.reason || "(unknown reason)";
|
|
257
|
+
return e.mark ? (e.mark.name && (n += 'in "' + e.mark.name + '" '), n += "(" + (e.mark.line + 1) + ":" + (e.mark.column + 1) + ")", !r && e.mark.snippet && (n += `
|
|
258
|
+
|
|
259
|
+
` + e.mark.snippet), i + " " + n) : i;
|
|
260
|
+
}
|
|
261
|
+
function q(e, r) {
|
|
262
|
+
Error.call(this), this.name = "YAMLException", this.reason = e, this.mark = r, this.message = Ee(this, !1), Error.captureStackTrace ? Error.captureStackTrace(this, this.constructor) : this.stack = new Error().stack || "";
|
|
263
|
+
}
|
|
264
|
+
q.prototype = Object.create(Error.prototype);
|
|
265
|
+
q.prototype.constructor = q;
|
|
266
|
+
q.prototype.toString = function(r) {
|
|
267
|
+
return this.name + ": " + Ee(this, r);
|
|
268
|
+
};
|
|
269
|
+
var N = q, Ve = [
|
|
270
|
+
"kind",
|
|
271
|
+
"multi",
|
|
272
|
+
"resolve",
|
|
273
|
+
"construct",
|
|
274
|
+
"instanceOf",
|
|
275
|
+
"predicate",
|
|
276
|
+
"represent",
|
|
277
|
+
"representName",
|
|
278
|
+
"defaultStyle",
|
|
279
|
+
"styleAliases"
|
|
280
|
+
], ze = [
|
|
281
|
+
"scalar",
|
|
282
|
+
"sequence",
|
|
283
|
+
"mapping"
|
|
284
|
+
];
|
|
285
|
+
function Xe(e) {
|
|
286
|
+
var r = {};
|
|
287
|
+
return e !== null && Object.keys(e).forEach(function(n) {
|
|
288
|
+
e[n].forEach(function(i) {
|
|
289
|
+
r[String(i)] = n;
|
|
290
|
+
});
|
|
291
|
+
}), r;
|
|
292
|
+
}
|
|
293
|
+
function Ze(e, r) {
|
|
294
|
+
if (r = r || {}, Object.keys(r).forEach(function(n) {
|
|
295
|
+
if (Ve.indexOf(n) === -1)
|
|
296
|
+
throw new N('Unknown option "' + n + '" is met in definition of "' + e + '" YAML type.');
|
|
297
|
+
}), this.options = r, this.tag = e, this.kind = r.kind || null, this.resolve = r.resolve || function() {
|
|
298
|
+
return !0;
|
|
299
|
+
}, this.construct = r.construct || function(n) {
|
|
300
|
+
return n;
|
|
301
|
+
}, this.instanceOf = r.instanceOf || null, this.predicate = r.predicate || null, this.represent = r.represent || null, this.representName = r.representName || null, this.defaultStyle = r.defaultStyle || null, this.multi = r.multi || !1, this.styleAliases = Xe(r.styleAliases || null), ze.indexOf(this.kind) === -1)
|
|
302
|
+
throw new N('Unknown kind "' + this.kind + '" is specified for "' + e + '" YAML type.');
|
|
303
|
+
}
|
|
304
|
+
var S = Ze;
|
|
305
|
+
function re(e, r) {
|
|
306
|
+
var n = [];
|
|
307
|
+
return e[r].forEach(function(i) {
|
|
308
|
+
var t = n.length;
|
|
309
|
+
n.forEach(function(a, o) {
|
|
310
|
+
a.tag === i.tag && a.kind === i.kind && a.multi === i.multi && (t = o);
|
|
311
|
+
}), n[t] = i;
|
|
312
|
+
}), n;
|
|
313
|
+
}
|
|
314
|
+
function Je() {
|
|
315
|
+
var e = {
|
|
316
|
+
scalar: {},
|
|
317
|
+
sequence: {},
|
|
318
|
+
mapping: {},
|
|
319
|
+
fallback: {},
|
|
320
|
+
multi: {
|
|
321
|
+
scalar: [],
|
|
322
|
+
sequence: [],
|
|
323
|
+
mapping: [],
|
|
324
|
+
fallback: []
|
|
325
|
+
}
|
|
326
|
+
}, r, n;
|
|
327
|
+
function i(t) {
|
|
328
|
+
t.multi ? (e.multi[t.kind].push(t), e.multi.fallback.push(t)) : e[t.kind][t.tag] = e.fallback[t.tag] = t;
|
|
329
|
+
}
|
|
330
|
+
for (r = 0, n = arguments.length; r < n; r += 1)
|
|
331
|
+
arguments[r].forEach(i);
|
|
332
|
+
return e;
|
|
333
|
+
}
|
|
334
|
+
function W(e) {
|
|
335
|
+
return this.extend(e);
|
|
336
|
+
}
|
|
337
|
+
W.prototype.extend = function(r) {
|
|
338
|
+
var n = [], i = [];
|
|
339
|
+
if (r instanceof S)
|
|
340
|
+
i.push(r);
|
|
341
|
+
else if (Array.isArray(r))
|
|
342
|
+
i = i.concat(r);
|
|
343
|
+
else if (r && (Array.isArray(r.implicit) || Array.isArray(r.explicit)))
|
|
344
|
+
r.implicit && (n = n.concat(r.implicit)), r.explicit && (i = i.concat(r.explicit));
|
|
345
|
+
else
|
|
346
|
+
throw new N("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");
|
|
347
|
+
n.forEach(function(a) {
|
|
348
|
+
if (!(a instanceof S))
|
|
349
|
+
throw new N("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
350
|
+
if (a.loadKind && a.loadKind !== "scalar")
|
|
351
|
+
throw new N("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
|
|
352
|
+
if (a.multi)
|
|
353
|
+
throw new N("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
|
|
354
|
+
}), i.forEach(function(a) {
|
|
355
|
+
if (!(a instanceof S))
|
|
356
|
+
throw new N("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
357
|
+
});
|
|
358
|
+
var t = Object.create(W.prototype);
|
|
359
|
+
return t.implicit = (this.implicit || []).concat(n), t.explicit = (this.explicit || []).concat(i), t.compiledImplicit = re(t, "implicit"), t.compiledExplicit = re(t, "explicit"), t.compiledTypeMap = Je(t.compiledImplicit, t.compiledExplicit), t;
|
|
360
|
+
};
|
|
361
|
+
var er = W, rr = new S("tag:yaml.org,2002:str", {
|
|
362
|
+
kind: "scalar",
|
|
363
|
+
construct: function(e) {
|
|
364
|
+
return e !== null ? e : "";
|
|
365
|
+
}
|
|
366
|
+
}), nr = new S("tag:yaml.org,2002:seq", {
|
|
367
|
+
kind: "sequence",
|
|
368
|
+
construct: function(e) {
|
|
369
|
+
return e !== null ? e : [];
|
|
370
|
+
}
|
|
371
|
+
}), tr = new S("tag:yaml.org,2002:map", {
|
|
372
|
+
kind: "mapping",
|
|
373
|
+
construct: function(e) {
|
|
374
|
+
return e !== null ? e : {};
|
|
375
|
+
}
|
|
376
|
+
}), ir = new er({
|
|
377
|
+
explicit: [
|
|
378
|
+
rr,
|
|
379
|
+
nr,
|
|
380
|
+
tr
|
|
381
|
+
]
|
|
382
|
+
});
|
|
383
|
+
function or(e) {
|
|
384
|
+
if (e === null) return !0;
|
|
385
|
+
var r = e.length;
|
|
386
|
+
return r === 1 && e === "~" || r === 4 && (e === "null" || e === "Null" || e === "NULL");
|
|
387
|
+
}
|
|
388
|
+
function ar() {
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
function lr(e) {
|
|
392
|
+
return e === null;
|
|
393
|
+
}
|
|
394
|
+
var sr = new S("tag:yaml.org,2002:null", {
|
|
395
|
+
kind: "scalar",
|
|
396
|
+
resolve: or,
|
|
397
|
+
construct: ar,
|
|
398
|
+
predicate: lr,
|
|
399
|
+
represent: {
|
|
400
|
+
canonical: function() {
|
|
401
|
+
return "~";
|
|
402
|
+
},
|
|
403
|
+
lowercase: function() {
|
|
404
|
+
return "null";
|
|
405
|
+
},
|
|
406
|
+
uppercase: function() {
|
|
407
|
+
return "NULL";
|
|
408
|
+
},
|
|
409
|
+
camelcase: function() {
|
|
410
|
+
return "Null";
|
|
411
|
+
},
|
|
412
|
+
empty: function() {
|
|
413
|
+
return "";
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
defaultStyle: "lowercase"
|
|
417
|
+
});
|
|
418
|
+
function ur(e) {
|
|
419
|
+
if (e === null) return !1;
|
|
420
|
+
var r = e.length;
|
|
421
|
+
return r === 4 && (e === "true" || e === "True" || e === "TRUE") || r === 5 && (e === "false" || e === "False" || e === "FALSE");
|
|
422
|
+
}
|
|
423
|
+
function cr(e) {
|
|
424
|
+
return e === "true" || e === "True" || e === "TRUE";
|
|
425
|
+
}
|
|
426
|
+
function fr(e) {
|
|
427
|
+
return Object.prototype.toString.call(e) === "[object Boolean]";
|
|
428
|
+
}
|
|
429
|
+
var pr = new S("tag:yaml.org,2002:bool", {
|
|
430
|
+
kind: "scalar",
|
|
431
|
+
resolve: ur,
|
|
432
|
+
construct: cr,
|
|
433
|
+
predicate: fr,
|
|
434
|
+
represent: {
|
|
435
|
+
lowercase: function(e) {
|
|
436
|
+
return e ? "true" : "false";
|
|
437
|
+
},
|
|
438
|
+
uppercase: function(e) {
|
|
439
|
+
return e ? "TRUE" : "FALSE";
|
|
440
|
+
},
|
|
441
|
+
camelcase: function(e) {
|
|
442
|
+
return e ? "True" : "False";
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
defaultStyle: "lowercase"
|
|
446
|
+
});
|
|
447
|
+
function mr(e) {
|
|
448
|
+
return 48 <= e && e <= 57 || 65 <= e && e <= 70 || 97 <= e && e <= 102;
|
|
449
|
+
}
|
|
450
|
+
function dr(e) {
|
|
451
|
+
return 48 <= e && e <= 55;
|
|
452
|
+
}
|
|
453
|
+
function yr(e) {
|
|
454
|
+
return 48 <= e && e <= 57;
|
|
455
|
+
}
|
|
456
|
+
function gr(e) {
|
|
457
|
+
if (e === null) return !1;
|
|
458
|
+
var r = e.length, n = 0, i = !1, t;
|
|
459
|
+
if (!r) return !1;
|
|
460
|
+
if (t = e[n], (t === "-" || t === "+") && (t = e[++n]), t === "0") {
|
|
461
|
+
if (n + 1 === r) return !0;
|
|
462
|
+
if (t = e[++n], t === "b") {
|
|
463
|
+
for (n++; n < r; n++)
|
|
464
|
+
if (t = e[n], t !== "_") {
|
|
465
|
+
if (t !== "0" && t !== "1") return !1;
|
|
466
|
+
i = !0;
|
|
467
|
+
}
|
|
468
|
+
return i && t !== "_";
|
|
469
|
+
}
|
|
470
|
+
if (t === "x") {
|
|
471
|
+
for (n++; n < r; n++)
|
|
472
|
+
if (t = e[n], t !== "_") {
|
|
473
|
+
if (!mr(e.charCodeAt(n))) return !1;
|
|
474
|
+
i = !0;
|
|
475
|
+
}
|
|
476
|
+
return i && t !== "_";
|
|
477
|
+
}
|
|
478
|
+
if (t === "o") {
|
|
479
|
+
for (n++; n < r; n++)
|
|
480
|
+
if (t = e[n], t !== "_") {
|
|
481
|
+
if (!dr(e.charCodeAt(n))) return !1;
|
|
482
|
+
i = !0;
|
|
483
|
+
}
|
|
484
|
+
return i && t !== "_";
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (t === "_") return !1;
|
|
488
|
+
for (; n < r; n++)
|
|
489
|
+
if (t = e[n], t !== "_") {
|
|
490
|
+
if (!yr(e.charCodeAt(n)))
|
|
491
|
+
return !1;
|
|
492
|
+
i = !0;
|
|
493
|
+
}
|
|
494
|
+
return !(!i || t === "_");
|
|
495
|
+
}
|
|
496
|
+
function hr(e) {
|
|
497
|
+
var r = e, n = 1, i;
|
|
498
|
+
if (r.indexOf("_") !== -1 && (r = r.replace(/_/g, "")), i = r[0], (i === "-" || i === "+") && (i === "-" && (n = -1), r = r.slice(1), i = r[0]), r === "0") return 0;
|
|
499
|
+
if (i === "0") {
|
|
500
|
+
if (r[1] === "b") return n * parseInt(r.slice(2), 2);
|
|
501
|
+
if (r[1] === "x") return n * parseInt(r.slice(2), 16);
|
|
502
|
+
if (r[1] === "o") return n * parseInt(r.slice(2), 8);
|
|
503
|
+
}
|
|
504
|
+
return n * parseInt(r, 10);
|
|
505
|
+
}
|
|
506
|
+
function Er(e) {
|
|
507
|
+
return Object.prototype.toString.call(e) === "[object Number]" && e % 1 === 0 && !$.isNegativeZero(e);
|
|
508
|
+
}
|
|
509
|
+
var Sr = new S("tag:yaml.org,2002:int", {
|
|
510
|
+
kind: "scalar",
|
|
511
|
+
resolve: gr,
|
|
512
|
+
construct: hr,
|
|
513
|
+
predicate: Er,
|
|
514
|
+
represent: {
|
|
515
|
+
binary: function(e) {
|
|
516
|
+
return e >= 0 ? "0b" + e.toString(2) : "-0b" + e.toString(2).slice(1);
|
|
517
|
+
},
|
|
518
|
+
octal: function(e) {
|
|
519
|
+
return e >= 0 ? "0o" + e.toString(8) : "-0o" + e.toString(8).slice(1);
|
|
520
|
+
},
|
|
521
|
+
decimal: function(e) {
|
|
522
|
+
return e.toString(10);
|
|
523
|
+
},
|
|
524
|
+
/* eslint-disable max-len */
|
|
525
|
+
hexadecimal: function(e) {
|
|
526
|
+
return e >= 0 ? "0x" + e.toString(16).toUpperCase() : "-0x" + e.toString(16).toUpperCase().slice(1);
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
defaultStyle: "decimal",
|
|
530
|
+
styleAliases: {
|
|
531
|
+
binary: [2, "bin"],
|
|
532
|
+
octal: [8, "oct"],
|
|
533
|
+
decimal: [10, "dec"],
|
|
534
|
+
hexadecimal: [16, "hex"]
|
|
535
|
+
}
|
|
536
|
+
}), xr = new RegExp(
|
|
537
|
+
// 2.5e4, 2.5 and integers
|
|
538
|
+
"^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"
|
|
539
|
+
);
|
|
540
|
+
function vr(e) {
|
|
541
|
+
return !(e === null || !xr.test(e) || // Quick hack to not allow integers end with `_`
|
|
542
|
+
// Probably should update regexp & check speed
|
|
543
|
+
e[e.length - 1] === "_");
|
|
544
|
+
}
|
|
545
|
+
function Ar(e) {
|
|
546
|
+
var r, n;
|
|
547
|
+
return r = e.replace(/_/g, "").toLowerCase(), n = r[0] === "-" ? -1 : 1, "+-".indexOf(r[0]) >= 0 && (r = r.slice(1)), r === ".inf" ? n === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY : r === ".nan" ? NaN : n * parseFloat(r, 10);
|
|
548
|
+
}
|
|
549
|
+
var Nr = /^[-+]?[0-9]+e/;
|
|
550
|
+
function wr(e, r) {
|
|
551
|
+
var n;
|
|
552
|
+
if (isNaN(e))
|
|
553
|
+
switch (r) {
|
|
554
|
+
case "lowercase":
|
|
555
|
+
return ".nan";
|
|
556
|
+
case "uppercase":
|
|
557
|
+
return ".NAN";
|
|
558
|
+
case "camelcase":
|
|
559
|
+
return ".NaN";
|
|
560
|
+
}
|
|
561
|
+
else if (Number.POSITIVE_INFINITY === e)
|
|
562
|
+
switch (r) {
|
|
563
|
+
case "lowercase":
|
|
564
|
+
return ".inf";
|
|
565
|
+
case "uppercase":
|
|
566
|
+
return ".INF";
|
|
567
|
+
case "camelcase":
|
|
568
|
+
return ".Inf";
|
|
569
|
+
}
|
|
570
|
+
else if (Number.NEGATIVE_INFINITY === e)
|
|
571
|
+
switch (r) {
|
|
572
|
+
case "lowercase":
|
|
573
|
+
return "-.inf";
|
|
574
|
+
case "uppercase":
|
|
575
|
+
return "-.INF";
|
|
576
|
+
case "camelcase":
|
|
577
|
+
return "-.Inf";
|
|
578
|
+
}
|
|
579
|
+
else if ($.isNegativeZero(e))
|
|
580
|
+
return "-0.0";
|
|
581
|
+
return n = e.toString(10), Nr.test(n) ? n.replace("e", ".e") : n;
|
|
582
|
+
}
|
|
583
|
+
function Rr(e) {
|
|
584
|
+
return Object.prototype.toString.call(e) === "[object Number]" && (e % 1 !== 0 || $.isNegativeZero(e));
|
|
585
|
+
}
|
|
586
|
+
var Tr = new S("tag:yaml.org,2002:float", {
|
|
587
|
+
kind: "scalar",
|
|
588
|
+
resolve: vr,
|
|
589
|
+
construct: Ar,
|
|
590
|
+
predicate: Rr,
|
|
591
|
+
represent: wr,
|
|
592
|
+
defaultStyle: "lowercase"
|
|
593
|
+
}), _r = ir.extend({
|
|
594
|
+
implicit: [
|
|
595
|
+
sr,
|
|
596
|
+
pr,
|
|
597
|
+
Sr,
|
|
598
|
+
Tr
|
|
599
|
+
]
|
|
600
|
+
}), Cr = _r, Se = new RegExp(
|
|
601
|
+
"^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"
|
|
602
|
+
), xe = new RegExp(
|
|
603
|
+
"^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$"
|
|
604
|
+
);
|
|
605
|
+
function Or(e) {
|
|
606
|
+
return e === null ? !1 : Se.exec(e) !== null || xe.exec(e) !== null;
|
|
607
|
+
}
|
|
608
|
+
function br(e) {
|
|
609
|
+
var r, n, i, t, a, o, l, s = 0, u = null, f, p, c;
|
|
610
|
+
if (r = Se.exec(e), r === null && (r = xe.exec(e)), r === null) throw new Error("Date resolve error");
|
|
611
|
+
if (n = +r[1], i = +r[2] - 1, t = +r[3], !r[4])
|
|
612
|
+
return new Date(Date.UTC(n, i, t));
|
|
613
|
+
if (a = +r[4], o = +r[5], l = +r[6], r[7]) {
|
|
614
|
+
for (s = r[7].slice(0, 3); s.length < 3; )
|
|
615
|
+
s += "0";
|
|
616
|
+
s = +s;
|
|
617
|
+
}
|
|
618
|
+
return r[9] && (f = +r[10], p = +(r[11] || 0), u = (f * 60 + p) * 6e4, r[9] === "-" && (u = -u)), c = new Date(Date.UTC(n, i, t, a, o, l, s)), u && c.setTime(c.getTime() - u), c;
|
|
619
|
+
}
|
|
620
|
+
function Ir(e) {
|
|
621
|
+
return e.toISOString();
|
|
622
|
+
}
|
|
623
|
+
var Lr = new S("tag:yaml.org,2002:timestamp", {
|
|
624
|
+
kind: "scalar",
|
|
625
|
+
resolve: Or,
|
|
626
|
+
construct: br,
|
|
627
|
+
instanceOf: Date,
|
|
628
|
+
represent: Ir
|
|
629
|
+
});
|
|
630
|
+
function Fr(e) {
|
|
631
|
+
return e === "<<" || e === null;
|
|
632
|
+
}
|
|
633
|
+
var $r = new S("tag:yaml.org,2002:merge", {
|
|
634
|
+
kind: "scalar",
|
|
635
|
+
resolve: Fr
|
|
636
|
+
}), J = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
|
|
637
|
+
\r`;
|
|
638
|
+
function Dr(e) {
|
|
639
|
+
if (e === null) return !1;
|
|
640
|
+
var r, n, i = 0, t = e.length, a = J;
|
|
641
|
+
for (n = 0; n < t; n++)
|
|
642
|
+
if (r = a.indexOf(e.charAt(n)), !(r > 64)) {
|
|
643
|
+
if (r < 0) return !1;
|
|
644
|
+
i += 6;
|
|
645
|
+
}
|
|
646
|
+
return i % 8 === 0;
|
|
647
|
+
}
|
|
648
|
+
function Mr(e) {
|
|
649
|
+
var r, n, i = e.replace(/[\r\n=]/g, ""), t = i.length, a = J, o = 0, l = [];
|
|
650
|
+
for (r = 0; r < t; r++)
|
|
651
|
+
r % 4 === 0 && r && (l.push(o >> 16 & 255), l.push(o >> 8 & 255), l.push(o & 255)), o = o << 6 | a.indexOf(i.charAt(r));
|
|
652
|
+
return n = t % 4 * 6, n === 0 ? (l.push(o >> 16 & 255), l.push(o >> 8 & 255), l.push(o & 255)) : n === 18 ? (l.push(o >> 10 & 255), l.push(o >> 2 & 255)) : n === 12 && l.push(o >> 4 & 255), new Uint8Array(l);
|
|
653
|
+
}
|
|
654
|
+
function kr(e) {
|
|
655
|
+
var r = "", n = 0, i, t, a = e.length, o = J;
|
|
656
|
+
for (i = 0; i < a; i++)
|
|
657
|
+
i % 3 === 0 && i && (r += o[n >> 18 & 63], r += o[n >> 12 & 63], r += o[n >> 6 & 63], r += o[n & 63]), n = (n << 8) + e[i];
|
|
658
|
+
return t = a % 3, t === 0 ? (r += o[n >> 18 & 63], r += o[n >> 12 & 63], r += o[n >> 6 & 63], r += o[n & 63]) : t === 2 ? (r += o[n >> 10 & 63], r += o[n >> 4 & 63], r += o[n << 2 & 63], r += o[64]) : t === 1 && (r += o[n >> 2 & 63], r += o[n << 4 & 63], r += o[64], r += o[64]), r;
|
|
659
|
+
}
|
|
660
|
+
function Pr(e) {
|
|
661
|
+
return Object.prototype.toString.call(e) === "[object Uint8Array]";
|
|
662
|
+
}
|
|
663
|
+
var Ur = new S("tag:yaml.org,2002:binary", {
|
|
664
|
+
kind: "scalar",
|
|
665
|
+
resolve: Dr,
|
|
666
|
+
construct: Mr,
|
|
667
|
+
predicate: Pr,
|
|
668
|
+
represent: kr
|
|
669
|
+
}), Yr = Object.prototype.hasOwnProperty, qr = Object.prototype.toString;
|
|
670
|
+
function jr(e) {
|
|
671
|
+
if (e === null) return !0;
|
|
672
|
+
var r = [], n, i, t, a, o, l = e;
|
|
673
|
+
for (n = 0, i = l.length; n < i; n += 1) {
|
|
674
|
+
if (t = l[n], o = !1, qr.call(t) !== "[object Object]") return !1;
|
|
675
|
+
for (a in t)
|
|
676
|
+
if (Yr.call(t, a))
|
|
677
|
+
if (!o) o = !0;
|
|
678
|
+
else return !1;
|
|
679
|
+
if (!o) return !1;
|
|
680
|
+
if (r.indexOf(a) === -1) r.push(a);
|
|
681
|
+
else return !1;
|
|
682
|
+
}
|
|
683
|
+
return !0;
|
|
684
|
+
}
|
|
685
|
+
function Hr(e) {
|
|
686
|
+
return e !== null ? e : [];
|
|
687
|
+
}
|
|
688
|
+
var Br = new S("tag:yaml.org,2002:omap", {
|
|
689
|
+
kind: "sequence",
|
|
690
|
+
resolve: jr,
|
|
691
|
+
construct: Hr
|
|
692
|
+
}), Kr = Object.prototype.toString;
|
|
693
|
+
function Gr(e) {
|
|
694
|
+
if (e === null) return !0;
|
|
695
|
+
var r, n, i, t, a, o = e;
|
|
696
|
+
for (a = new Array(o.length), r = 0, n = o.length; r < n; r += 1) {
|
|
697
|
+
if (i = o[r], Kr.call(i) !== "[object Object]" || (t = Object.keys(i), t.length !== 1)) return !1;
|
|
698
|
+
a[r] = [t[0], i[t[0]]];
|
|
699
|
+
}
|
|
700
|
+
return !0;
|
|
701
|
+
}
|
|
702
|
+
function Qr(e) {
|
|
703
|
+
if (e === null) return [];
|
|
704
|
+
var r, n, i, t, a, o = e;
|
|
705
|
+
for (a = new Array(o.length), r = 0, n = o.length; r < n; r += 1)
|
|
706
|
+
i = o[r], t = Object.keys(i), a[r] = [t[0], i[t[0]]];
|
|
707
|
+
return a;
|
|
708
|
+
}
|
|
709
|
+
var Wr = new S("tag:yaml.org,2002:pairs", {
|
|
710
|
+
kind: "sequence",
|
|
711
|
+
resolve: Gr,
|
|
712
|
+
construct: Qr
|
|
713
|
+
}), Vr = Object.prototype.hasOwnProperty;
|
|
714
|
+
function zr(e) {
|
|
715
|
+
if (e === null) return !0;
|
|
716
|
+
var r, n = e;
|
|
717
|
+
for (r in n)
|
|
718
|
+
if (Vr.call(n, r) && n[r] !== null)
|
|
719
|
+
return !1;
|
|
720
|
+
return !0;
|
|
721
|
+
}
|
|
722
|
+
function Xr(e) {
|
|
723
|
+
return e !== null ? e : {};
|
|
724
|
+
}
|
|
725
|
+
var Zr = new S("tag:yaml.org,2002:set", {
|
|
726
|
+
kind: "mapping",
|
|
727
|
+
resolve: zr,
|
|
728
|
+
construct: Xr
|
|
729
|
+
}), Jr = Cr.extend({
|
|
730
|
+
implicit: [
|
|
731
|
+
Lr,
|
|
732
|
+
$r
|
|
733
|
+
],
|
|
734
|
+
explicit: [
|
|
735
|
+
Ur,
|
|
736
|
+
Br,
|
|
737
|
+
Wr,
|
|
738
|
+
Zr
|
|
739
|
+
]
|
|
740
|
+
});
|
|
741
|
+
function ne(e) {
|
|
742
|
+
return e === 48 ? "\0" : e === 97 ? "\x07" : e === 98 ? "\b" : e === 116 || e === 9 ? " " : e === 110 ? `
|
|
743
|
+
` : e === 118 ? "\v" : e === 102 ? "\f" : e === 114 ? "\r" : e === 101 ? "\x1B" : e === 32 ? " " : e === 34 ? '"' : e === 47 ? "/" : e === 92 ? "\\" : e === 78 ? "
" : e === 95 ? " " : e === 76 ? "\u2028" : e === 80 ? "\u2029" : "";
|
|
744
|
+
}
|
|
745
|
+
var en = new Array(256), rn = new Array(256);
|
|
746
|
+
for (var D = 0; D < 256; D++)
|
|
747
|
+
en[D] = ne(D) ? 1 : 0, rn[D] = ne(D);
|
|
748
|
+
var ve = Object.prototype.toString, Ae = Object.prototype.hasOwnProperty, ee = 65279, nn = 9, j = 10, tn = 13, on = 32, an = 33, ln = 34, V = 35, sn = 37, un = 38, cn = 39, fn = 42, Ne = 44, pn = 45, K = 58, mn = 61, dn = 62, yn = 63, gn = 64, we = 91, Re = 93, hn = 96, Te = 123, En = 124, _e = 125, x = {};
|
|
749
|
+
x[0] = "\\0";
|
|
750
|
+
x[7] = "\\a";
|
|
751
|
+
x[8] = "\\b";
|
|
752
|
+
x[9] = "\\t";
|
|
753
|
+
x[10] = "\\n";
|
|
754
|
+
x[11] = "\\v";
|
|
755
|
+
x[12] = "\\f";
|
|
756
|
+
x[13] = "\\r";
|
|
757
|
+
x[27] = "\\e";
|
|
758
|
+
x[34] = '\\"';
|
|
759
|
+
x[92] = "\\\\";
|
|
760
|
+
x[133] = "\\N";
|
|
761
|
+
x[160] = "\\_";
|
|
762
|
+
x[8232] = "\\L";
|
|
763
|
+
x[8233] = "\\P";
|
|
764
|
+
var Sn = [
|
|
765
|
+
"y",
|
|
766
|
+
"Y",
|
|
767
|
+
"yes",
|
|
768
|
+
"Yes",
|
|
769
|
+
"YES",
|
|
770
|
+
"on",
|
|
771
|
+
"On",
|
|
772
|
+
"ON",
|
|
773
|
+
"n",
|
|
774
|
+
"N",
|
|
775
|
+
"no",
|
|
776
|
+
"No",
|
|
777
|
+
"NO",
|
|
778
|
+
"off",
|
|
779
|
+
"Off",
|
|
780
|
+
"OFF"
|
|
781
|
+
], xn = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
|
|
782
|
+
function vn(e, r) {
|
|
783
|
+
var n, i, t, a, o, l, s;
|
|
784
|
+
if (r === null) return {};
|
|
785
|
+
for (n = {}, i = Object.keys(r), t = 0, a = i.length; t < a; t += 1)
|
|
786
|
+
o = i[t], l = String(r[o]), o.slice(0, 2) === "!!" && (o = "tag:yaml.org,2002:" + o.slice(2)), s = e.compiledTypeMap.fallback[o], s && Ae.call(s.styleAliases, l) && (l = s.styleAliases[l]), n[o] = l;
|
|
787
|
+
return n;
|
|
788
|
+
}
|
|
789
|
+
function An(e) {
|
|
790
|
+
var r, n, i;
|
|
791
|
+
if (r = e.toString(16).toUpperCase(), e <= 255)
|
|
792
|
+
n = "x", i = 2;
|
|
793
|
+
else if (e <= 65535)
|
|
794
|
+
n = "u", i = 4;
|
|
795
|
+
else if (e <= 4294967295)
|
|
796
|
+
n = "U", i = 8;
|
|
797
|
+
else
|
|
798
|
+
throw new N("code point within a string may not be greater than 0xFFFFFFFF");
|
|
799
|
+
return "\\" + n + $.repeat("0", i - r.length) + r;
|
|
800
|
+
}
|
|
801
|
+
var Nn = 1, H = 2;
|
|
802
|
+
function wn(e) {
|
|
803
|
+
this.schema = e.schema || Jr, this.indent = Math.max(1, e.indent || 2), this.noArrayIndent = e.noArrayIndent || !1, this.skipInvalid = e.skipInvalid || !1, this.flowLevel = $.isNothing(e.flowLevel) ? -1 : e.flowLevel, this.styleMap = vn(this.schema, e.styles || null), this.sortKeys = e.sortKeys || !1, this.lineWidth = e.lineWidth || 80, this.noRefs = e.noRefs || !1, this.noCompatMode = e.noCompatMode || !1, this.condenseFlow = e.condenseFlow || !1, this.quotingType = e.quotingType === '"' ? H : Nn, this.forceQuotes = e.forceQuotes || !1, this.replacer = typeof e.replacer == "function" ? e.replacer : null, this.implicitTypes = this.schema.compiledImplicit, this.explicitTypes = this.schema.compiledExplicit, this.tag = null, this.result = "", this.duplicates = [], this.usedDuplicates = null;
|
|
804
|
+
}
|
|
805
|
+
function te(e, r) {
|
|
806
|
+
for (var n = $.repeat(" ", r), i = 0, t = -1, a = "", o, l = e.length; i < l; )
|
|
807
|
+
t = e.indexOf(`
|
|
808
|
+
`, i), t === -1 ? (o = e.slice(i), i = l) : (o = e.slice(i, t + 1), i = t + 1), o.length && o !== `
|
|
809
|
+
` && (a += n), a += o;
|
|
810
|
+
return a;
|
|
811
|
+
}
|
|
812
|
+
function z(e, r) {
|
|
813
|
+
return `
|
|
814
|
+
` + $.repeat(" ", e.indent * r);
|
|
815
|
+
}
|
|
816
|
+
function Rn(e, r) {
|
|
817
|
+
var n, i, t;
|
|
818
|
+
for (n = 0, i = e.implicitTypes.length; n < i; n += 1)
|
|
819
|
+
if (t = e.implicitTypes[n], t.resolve(r))
|
|
820
|
+
return !0;
|
|
821
|
+
return !1;
|
|
822
|
+
}
|
|
823
|
+
function G(e) {
|
|
824
|
+
return e === on || e === nn;
|
|
825
|
+
}
|
|
826
|
+
function B(e) {
|
|
827
|
+
return 32 <= e && e <= 126 || 161 <= e && e <= 55295 && e !== 8232 && e !== 8233 || 57344 <= e && e <= 65533 && e !== ee || 65536 <= e && e <= 1114111;
|
|
828
|
+
}
|
|
829
|
+
function ie(e) {
|
|
830
|
+
return B(e) && e !== ee && e !== tn && e !== j;
|
|
831
|
+
}
|
|
832
|
+
function oe(e, r, n) {
|
|
833
|
+
var i = ie(e), t = i && !G(e);
|
|
834
|
+
return (
|
|
835
|
+
// ns-plain-safe
|
|
836
|
+
(n ? (
|
|
837
|
+
// c = flow-in
|
|
838
|
+
i
|
|
839
|
+
) : i && e !== Ne && e !== we && e !== Re && e !== Te && e !== _e) && e !== V && !(r === K && !t) || ie(r) && !G(r) && e === V || r === K && t
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
function Tn(e) {
|
|
843
|
+
return B(e) && e !== ee && !G(e) && e !== pn && e !== yn && e !== K && e !== Ne && e !== we && e !== Re && e !== Te && e !== _e && e !== V && e !== un && e !== fn && e !== an && e !== En && e !== mn && e !== dn && e !== cn && e !== ln && e !== sn && e !== gn && e !== hn;
|
|
844
|
+
}
|
|
845
|
+
function _n(e) {
|
|
846
|
+
return !G(e) && e !== K;
|
|
847
|
+
}
|
|
848
|
+
function Y(e, r) {
|
|
849
|
+
var n = e.charCodeAt(r), i;
|
|
850
|
+
return n >= 55296 && n <= 56319 && r + 1 < e.length && (i = e.charCodeAt(r + 1), i >= 56320 && i <= 57343) ? (n - 55296) * 1024 + i - 56320 + 65536 : n;
|
|
851
|
+
}
|
|
852
|
+
function Ce(e) {
|
|
853
|
+
var r = /^\n* /;
|
|
854
|
+
return r.test(e);
|
|
855
|
+
}
|
|
856
|
+
var Oe = 1, X = 2, be = 3, Ie = 4, M = 5;
|
|
857
|
+
function Cn(e, r, n, i, t, a, o, l) {
|
|
858
|
+
var s, u = 0, f = null, p = !1, c = !1, d = i !== -1, E = -1, h = Tn(Y(e, 0)) && _n(Y(e, e.length - 1));
|
|
859
|
+
if (r || o)
|
|
860
|
+
for (s = 0; s < e.length; u >= 65536 ? s += 2 : s++) {
|
|
861
|
+
if (u = Y(e, s), !B(u))
|
|
862
|
+
return M;
|
|
863
|
+
h = h && oe(u, f, l), f = u;
|
|
864
|
+
}
|
|
865
|
+
else {
|
|
866
|
+
for (s = 0; s < e.length; u >= 65536 ? s += 2 : s++) {
|
|
867
|
+
if (u = Y(e, s), u === j)
|
|
868
|
+
p = !0, d && (c = c || // Foldable line = too long, and not more-indented.
|
|
869
|
+
s - E - 1 > i && e[E + 1] !== " ", E = s);
|
|
870
|
+
else if (!B(u))
|
|
871
|
+
return M;
|
|
872
|
+
h = h && oe(u, f, l), f = u;
|
|
873
|
+
}
|
|
874
|
+
c = c || d && s - E - 1 > i && e[E + 1] !== " ";
|
|
875
|
+
}
|
|
876
|
+
return !p && !c ? h && !o && !t(e) ? Oe : a === H ? M : X : n > 9 && Ce(e) ? M : o ? a === H ? M : X : c ? Ie : be;
|
|
877
|
+
}
|
|
878
|
+
function On(e, r, n, i, t) {
|
|
879
|
+
e.dump = function() {
|
|
880
|
+
if (r.length === 0)
|
|
881
|
+
return e.quotingType === H ? '""' : "''";
|
|
882
|
+
if (!e.noCompatMode && (Sn.indexOf(r) !== -1 || xn.test(r)))
|
|
883
|
+
return e.quotingType === H ? '"' + r + '"' : "'" + r + "'";
|
|
884
|
+
var a = e.indent * Math.max(1, n), o = e.lineWidth === -1 ? -1 : Math.max(Math.min(e.lineWidth, 40), e.lineWidth - a), l = i || e.flowLevel > -1 && n >= e.flowLevel;
|
|
885
|
+
function s(u) {
|
|
886
|
+
return Rn(e, u);
|
|
887
|
+
}
|
|
888
|
+
switch (Cn(
|
|
889
|
+
r,
|
|
890
|
+
l,
|
|
891
|
+
e.indent,
|
|
892
|
+
o,
|
|
893
|
+
s,
|
|
894
|
+
e.quotingType,
|
|
895
|
+
e.forceQuotes && !i,
|
|
896
|
+
t
|
|
897
|
+
)) {
|
|
898
|
+
case Oe:
|
|
899
|
+
return r;
|
|
900
|
+
case X:
|
|
901
|
+
return "'" + r.replace(/'/g, "''") + "'";
|
|
902
|
+
case be:
|
|
903
|
+
return "|" + ae(r, e.indent) + le(te(r, a));
|
|
904
|
+
case Ie:
|
|
905
|
+
return ">" + ae(r, e.indent) + le(te(bn(r, o), a));
|
|
906
|
+
case M:
|
|
907
|
+
return '"' + In(r) + '"';
|
|
908
|
+
default:
|
|
909
|
+
throw new N("impossible error: invalid scalar style");
|
|
910
|
+
}
|
|
911
|
+
}();
|
|
912
|
+
}
|
|
913
|
+
function ae(e, r) {
|
|
914
|
+
var n = Ce(e) ? String(r) : "", i = e[e.length - 1] === `
|
|
915
|
+
`, t = i && (e[e.length - 2] === `
|
|
916
|
+
` || e === `
|
|
917
|
+
`), a = t ? "+" : i ? "" : "-";
|
|
918
|
+
return n + a + `
|
|
919
|
+
`;
|
|
920
|
+
}
|
|
921
|
+
function le(e) {
|
|
922
|
+
return e[e.length - 1] === `
|
|
923
|
+
` ? e.slice(0, -1) : e;
|
|
924
|
+
}
|
|
925
|
+
function bn(e, r) {
|
|
926
|
+
for (var n = /(\n+)([^\n]*)/g, i = function() {
|
|
927
|
+
var u = e.indexOf(`
|
|
928
|
+
`);
|
|
929
|
+
return u = u !== -1 ? u : e.length, n.lastIndex = u, se(e.slice(0, u), r);
|
|
930
|
+
}(), t = e[0] === `
|
|
931
|
+
` || e[0] === " ", a, o; o = n.exec(e); ) {
|
|
932
|
+
var l = o[1], s = o[2];
|
|
933
|
+
a = s[0] === " ", i += l + (!t && !a && s !== "" ? `
|
|
934
|
+
` : "") + se(s, r), t = a;
|
|
935
|
+
}
|
|
936
|
+
return i;
|
|
937
|
+
}
|
|
938
|
+
function se(e, r) {
|
|
939
|
+
if (e === "" || e[0] === " ") return e;
|
|
940
|
+
for (var n = / [^ ]/g, i, t = 0, a, o = 0, l = 0, s = ""; i = n.exec(e); )
|
|
941
|
+
l = i.index, l - t > r && (a = o > t ? o : l, s += `
|
|
942
|
+
` + e.slice(t, a), t = a + 1), o = l;
|
|
943
|
+
return s += `
|
|
944
|
+
`, e.length - t > r && o > t ? s += e.slice(t, o) + `
|
|
945
|
+
` + e.slice(o + 1) : s += e.slice(t), s.slice(1);
|
|
946
|
+
}
|
|
947
|
+
function In(e) {
|
|
948
|
+
for (var r = "", n = 0, i, t = 0; t < e.length; n >= 65536 ? t += 2 : t++)
|
|
949
|
+
n = Y(e, t), i = x[n], !i && B(n) ? (r += e[t], n >= 65536 && (r += e[t + 1])) : r += i || An(n);
|
|
950
|
+
return r;
|
|
951
|
+
}
|
|
952
|
+
function Ln(e, r, n) {
|
|
953
|
+
var i = "", t = e.tag, a, o, l;
|
|
954
|
+
for (a = 0, o = n.length; a < o; a += 1)
|
|
955
|
+
l = n[a], e.replacer && (l = e.replacer.call(n, String(a), l)), (R(e, r, l, !1, !1) || typeof l > "u" && R(e, r, null, !1, !1)) && (i !== "" && (i += "," + (e.condenseFlow ? "" : " ")), i += e.dump);
|
|
956
|
+
e.tag = t, e.dump = "[" + i + "]";
|
|
957
|
+
}
|
|
958
|
+
function ue(e, r, n, i) {
|
|
959
|
+
var t = "", a = e.tag, o, l, s;
|
|
960
|
+
for (o = 0, l = n.length; o < l; o += 1)
|
|
961
|
+
s = n[o], e.replacer && (s = e.replacer.call(n, String(o), s)), (R(e, r + 1, s, !0, !0, !1, !0) || typeof s > "u" && R(e, r + 1, null, !0, !0, !1, !0)) && ((!i || t !== "") && (t += z(e, r)), e.dump && j === e.dump.charCodeAt(0) ? t += "-" : t += "- ", t += e.dump);
|
|
962
|
+
e.tag = a, e.dump = t || "[]";
|
|
963
|
+
}
|
|
964
|
+
function Fn(e, r, n) {
|
|
965
|
+
var i = "", t = e.tag, a = Object.keys(n), o, l, s, u, f;
|
|
966
|
+
for (o = 0, l = a.length; o < l; o += 1)
|
|
967
|
+
f = "", i !== "" && (f += ", "), e.condenseFlow && (f += '"'), s = a[o], u = n[s], e.replacer && (u = e.replacer.call(n, s, u)), R(e, r, s, !1, !1) && (e.dump.length > 1024 && (f += "? "), f += e.dump + (e.condenseFlow ? '"' : "") + ":" + (e.condenseFlow ? "" : " "), R(e, r, u, !1, !1) && (f += e.dump, i += f));
|
|
968
|
+
e.tag = t, e.dump = "{" + i + "}";
|
|
969
|
+
}
|
|
970
|
+
function $n(e, r, n, i) {
|
|
971
|
+
var t = "", a = e.tag, o = Object.keys(n), l, s, u, f, p, c;
|
|
972
|
+
if (e.sortKeys === !0)
|
|
973
|
+
o.sort();
|
|
974
|
+
else if (typeof e.sortKeys == "function")
|
|
975
|
+
o.sort(e.sortKeys);
|
|
976
|
+
else if (e.sortKeys)
|
|
977
|
+
throw new N("sortKeys must be a boolean or a function");
|
|
978
|
+
for (l = 0, s = o.length; l < s; l += 1)
|
|
979
|
+
c = "", (!i || t !== "") && (c += z(e, r)), u = o[l], f = n[u], e.replacer && (f = e.replacer.call(n, u, f)), R(e, r + 1, u, !0, !0, !0) && (p = e.tag !== null && e.tag !== "?" || e.dump && e.dump.length > 1024, p && (e.dump && j === e.dump.charCodeAt(0) ? c += "?" : c += "? "), c += e.dump, p && (c += z(e, r)), R(e, r + 1, f, !0, p) && (e.dump && j === e.dump.charCodeAt(0) ? c += ":" : c += ": ", c += e.dump, t += c));
|
|
980
|
+
e.tag = a, e.dump = t || "{}";
|
|
981
|
+
}
|
|
982
|
+
function ce(e, r, n) {
|
|
983
|
+
var i, t, a, o, l, s;
|
|
984
|
+
for (t = n ? e.explicitTypes : e.implicitTypes, a = 0, o = t.length; a < o; a += 1)
|
|
985
|
+
if (l = t[a], (l.instanceOf || l.predicate) && (!l.instanceOf || typeof r == "object" && r instanceof l.instanceOf) && (!l.predicate || l.predicate(r))) {
|
|
986
|
+
if (n ? l.multi && l.representName ? e.tag = l.representName(r) : e.tag = l.tag : e.tag = "?", l.represent) {
|
|
987
|
+
if (s = e.styleMap[l.tag] || l.defaultStyle, ve.call(l.represent) === "[object Function]")
|
|
988
|
+
i = l.represent(r, s);
|
|
989
|
+
else if (Ae.call(l.represent, s))
|
|
990
|
+
i = l.represent[s](r, s);
|
|
991
|
+
else
|
|
992
|
+
throw new N("!<" + l.tag + '> tag resolver accepts not "' + s + '" style');
|
|
993
|
+
e.dump = i;
|
|
994
|
+
}
|
|
995
|
+
return !0;
|
|
996
|
+
}
|
|
997
|
+
return !1;
|
|
998
|
+
}
|
|
999
|
+
function R(e, r, n, i, t, a, o) {
|
|
1000
|
+
e.tag = null, e.dump = n, ce(e, n, !1) || ce(e, n, !0);
|
|
1001
|
+
var l = ve.call(e.dump), s = i, u;
|
|
1002
|
+
i && (i = e.flowLevel < 0 || e.flowLevel > r);
|
|
1003
|
+
var f = l === "[object Object]" || l === "[object Array]", p, c;
|
|
1004
|
+
if (f && (p = e.duplicates.indexOf(n), c = p !== -1), (e.tag !== null && e.tag !== "?" || c || e.indent !== 2 && r > 0) && (t = !1), c && e.usedDuplicates[p])
|
|
1005
|
+
e.dump = "*ref_" + p;
|
|
1006
|
+
else {
|
|
1007
|
+
if (f && c && !e.usedDuplicates[p] && (e.usedDuplicates[p] = !0), l === "[object Object]")
|
|
1008
|
+
i && Object.keys(e.dump).length !== 0 ? ($n(e, r, e.dump, t), c && (e.dump = "&ref_" + p + e.dump)) : (Fn(e, r, e.dump), c && (e.dump = "&ref_" + p + " " + e.dump));
|
|
1009
|
+
else if (l === "[object Array]")
|
|
1010
|
+
i && e.dump.length !== 0 ? (e.noArrayIndent && !o && r > 0 ? ue(e, r - 1, e.dump, t) : ue(e, r, e.dump, t), c && (e.dump = "&ref_" + p + e.dump)) : (Ln(e, r, e.dump), c && (e.dump = "&ref_" + p + " " + e.dump));
|
|
1011
|
+
else if (l === "[object String]")
|
|
1012
|
+
e.tag !== "?" && On(e, e.dump, r, a, s);
|
|
1013
|
+
else {
|
|
1014
|
+
if (l === "[object Undefined]")
|
|
1015
|
+
return !1;
|
|
1016
|
+
if (e.skipInvalid) return !1;
|
|
1017
|
+
throw new N("unacceptable kind of an object to dump " + l);
|
|
1018
|
+
}
|
|
1019
|
+
e.tag !== null && e.tag !== "?" && (u = encodeURI(
|
|
1020
|
+
e.tag[0] === "!" ? e.tag.slice(1) : e.tag
|
|
1021
|
+
).replace(/!/g, "%21"), e.tag[0] === "!" ? u = "!" + u : u.slice(0, 18) === "tag:yaml.org,2002:" ? u = "!!" + u.slice(18) : u = "!<" + u + ">", e.dump = u + " " + e.dump);
|
|
1022
|
+
}
|
|
1023
|
+
return !0;
|
|
1024
|
+
}
|
|
1025
|
+
function Dn(e, r) {
|
|
1026
|
+
var n = [], i = [], t, a;
|
|
1027
|
+
for (Z(e, n, i), t = 0, a = i.length; t < a; t += 1)
|
|
1028
|
+
r.duplicates.push(n[i[t]]);
|
|
1029
|
+
r.usedDuplicates = new Array(a);
|
|
1030
|
+
}
|
|
1031
|
+
function Z(e, r, n) {
|
|
1032
|
+
var i, t, a;
|
|
1033
|
+
if (e !== null && typeof e == "object")
|
|
1034
|
+
if (t = r.indexOf(e), t !== -1)
|
|
1035
|
+
n.indexOf(t) === -1 && n.push(t);
|
|
1036
|
+
else if (r.push(e), Array.isArray(e))
|
|
1037
|
+
for (t = 0, a = e.length; t < a; t += 1)
|
|
1038
|
+
Z(e[t], r, n);
|
|
1039
|
+
else
|
|
1040
|
+
for (i = Object.keys(e), t = 0, a = i.length; t < a; t += 1)
|
|
1041
|
+
Z(e[i[t]], r, n);
|
|
1042
|
+
}
|
|
1043
|
+
function Mn(e, r) {
|
|
1044
|
+
r = r || {};
|
|
1045
|
+
var n = new wn(r);
|
|
1046
|
+
n.noRefs || Dn(e, n);
|
|
1047
|
+
var i = e;
|
|
1048
|
+
return n.replacer && (i = n.replacer.call({ "": i }, "", i)), R(n, 0, i, !0, !0) ? n.dump + `
|
|
1049
|
+
` : "";
|
|
1050
|
+
}
|
|
1051
|
+
var kn = Mn, Pn = {
|
|
1052
|
+
dump: kn
|
|
1053
|
+
}, Un = Pn.dump;
|
|
1054
|
+
function Yn(e) {
|
|
1055
|
+
const r = [];
|
|
1056
|
+
for (const n of e.entityMetadatas) {
|
|
1057
|
+
if (typeof n.target == "string") continue;
|
|
1058
|
+
const i = n.target, t = _.isSecurityEnabled(i), a = _.getRLS(i), o = _.getCLS(i), l = _.getCustomSql(i);
|
|
1059
|
+
if (!t && (a.length > 0 || o.length > 0)) {
|
|
1060
|
+
console.warn(y.yellow(`${n.name}: Found Security decorators (@rls / @cls) but missing @security class decorator. Skipping.`));
|
|
1061
|
+
continue;
|
|
1062
|
+
}
|
|
1063
|
+
if (!t && l.length === 0) continue;
|
|
1064
|
+
const s = o.map((u) => {
|
|
1065
|
+
const f = n.columns.find((c) => c.propertyName === u.propertyKey);
|
|
1066
|
+
if (f)
|
|
1067
|
+
return { ...u, databaseName: f.databaseName };
|
|
1068
|
+
const p = n.relations.find((c) => c.propertyName === u.propertyKey);
|
|
1069
|
+
if (p) {
|
|
1070
|
+
if (p.joinColumns.length > 0)
|
|
1071
|
+
return { ...u, databaseName: p.joinColumns[0].databaseName };
|
|
1072
|
+
const c = n.columns.find((d) => d.relationMetadata === p);
|
|
1073
|
+
if (c)
|
|
1074
|
+
return { ...u, databaseName: c.databaseName };
|
|
1075
|
+
}
|
|
1076
|
+
throw console.error(y.red(`
|
|
1077
|
+
[supaforge debug] Property ${n.name}.${u.propertyKey} not found.`)), console.error(y.gray(`Available columns: ${n.columns.map((c) => c.propertyName).join(", ")}`)), console.error(y.gray(`Available relations: ${n.relations.map((c) => c.propertyName).join(", ")}`)), new Error(`Internal Sync Error: Database column not found for property ${n.name}.${u.propertyKey}`);
|
|
1078
|
+
});
|
|
1079
|
+
r.push({
|
|
1080
|
+
tableName: n.tableName,
|
|
1081
|
+
entityName: n.name,
|
|
1082
|
+
policies: a,
|
|
1083
|
+
columns: s,
|
|
1084
|
+
customSql: l,
|
|
1085
|
+
isSecurityEnabled: t
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
return r;
|
|
1089
|
+
}
|
|
1090
|
+
async function Le(e) {
|
|
1091
|
+
const r = [];
|
|
1092
|
+
if (!g.existsSync(e))
|
|
1093
|
+
throw new Error(`Cannot load entities. Path does not exist: ${e}`);
|
|
1094
|
+
const i = g.statSync(e).isDirectory() ? g.readdirSync(e).filter((t) => t.endsWith(".ts") || t.endsWith(".js")).map((t) => C.join(e, t)) : [e];
|
|
1095
|
+
for (const t of i)
|
|
1096
|
+
try {
|
|
1097
|
+
const a = await import(t);
|
|
1098
|
+
for (const o of Object.values(a))
|
|
1099
|
+
typeof o == "function" && o.name && r.push(o);
|
|
1100
|
+
} catch {
|
|
1101
|
+
console.warn(y.red(`Could not import entity file ${t}. Skipped.`));
|
|
1102
|
+
}
|
|
1103
|
+
return r;
|
|
1104
|
+
}
|
|
1105
|
+
function qn(e) {
|
|
1106
|
+
if (!g.existsSync(e)) return null;
|
|
1107
|
+
const n = g.readdirSync(e).map((i) => {
|
|
1108
|
+
const t = i.match(/^(\d+)-(.+)\.ts$/);
|
|
1109
|
+
return t && !i.toLowerCase().includes("_sec") ? {
|
|
1110
|
+
timestamp: t[1],
|
|
1111
|
+
name: t[2],
|
|
1112
|
+
filename: i
|
|
1113
|
+
} : null;
|
|
1114
|
+
}).filter((i) => i !== null).sort((i, t) => Number(t.timestamp) - Number(i.timestamp));
|
|
1115
|
+
return n.length > 0 ? { timestamp: n[0].timestamp, name: n[0].name } : null;
|
|
1116
|
+
}
|
|
1117
|
+
async function Xn(e) {
|
|
1118
|
+
const { entityPath: r, outputDir: n, dbConfig: i } = e, t = C.resolve(r);
|
|
1119
|
+
console.log(y.cyan("Syncing security..."));
|
|
1120
|
+
const a = await Le(t);
|
|
1121
|
+
if (a.length === 0)
|
|
1122
|
+
return console.info(y.yellow(`No entities found at ${t}`)), "";
|
|
1123
|
+
const o = new pe({
|
|
1124
|
+
type: "postgres",
|
|
1125
|
+
...i,
|
|
1126
|
+
username: i.user,
|
|
1127
|
+
synchronize: !!e.syncSchema,
|
|
1128
|
+
entities: a,
|
|
1129
|
+
logging: !1
|
|
1130
|
+
});
|
|
1131
|
+
await o.initialize(), e.syncSchema && (console.log(y.gray("Synchronizing schema...")), await o.synchronize());
|
|
1132
|
+
try {
|
|
1133
|
+
const l = Yn(o);
|
|
1134
|
+
if (l.length === 0)
|
|
1135
|
+
return console.info(y.green("No security decorators found.")), "";
|
|
1136
|
+
const s = ye(l, { cls: e.cls, rls: e.rls }), u = qn(n), f = u ? u.timestamp : String(Date.now()), c = `${e.migrationName || (u ? u.name : "SecuritySync")}_sec`.replace(/_sec_sec$/, "_sec"), d = `${c}${f}`, E = `${f}-${c}`;
|
|
1137
|
+
g.existsSync(n) || g.mkdirSync(n, { recursive: !0 });
|
|
1138
|
+
const h = C.join(n, `${E}.ts`), v = C.join(n, `${E}.sql`), O = ge(d, s);
|
|
1139
|
+
return g.writeFileSync(h, O), g.writeFileSync(v, s), console.log(y.green("Migration artifacts generated:")), console.log(y.gray(` TS -> ${h}`)), console.log(y.gray(` SQL -> ${v}`)), s;
|
|
1140
|
+
} finally {
|
|
1141
|
+
await o.destroy();
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
function Zn(e) {
|
|
1145
|
+
const { outputDir: r, migrationName: n = "ManualMigration" } = e;
|
|
1146
|
+
g.existsSync(r) || g.mkdirSync(r, { recursive: !0 });
|
|
1147
|
+
const i = String(Date.now()), t = `${n}${i}`, a = C.join(r, `${i}-${n}.ts`), o = ge(t, "-- Manual migration (Up)", "-- Manual migration (Down)");
|
|
1148
|
+
g.writeFileSync(a, o), console.log(y.green(`Blank migration stub ready at ${a}`));
|
|
1149
|
+
}
|
|
1150
|
+
async function Jn(e, r, n, i, t = []) {
|
|
1151
|
+
const a = Array.isArray(r) ? r : [r], o = a[0];
|
|
1152
|
+
await e.query("RESET ROLE"), await e.query("BEGIN");
|
|
1153
|
+
try {
|
|
1154
|
+
if (o !== "postgres" && o !== "supabase_admin") {
|
|
1155
|
+
const u = a.every((v) => Q.includes(v.toLowerCase())), f = a.length === 1 && !u ? a[0] : null, p = a.filter((v) => !Q.includes(v.toLowerCase())), c = { sub: n, role: u ? a[0] : "authenticated" };
|
|
1156
|
+
f && (c.user_role = f), p.length > 0 && (c.user_roles = p);
|
|
1157
|
+
const E = JSON.stringify(c).replace(/'/g, "''"), h = n.replace(/'/g, "''");
|
|
1158
|
+
if (await e.query(`SET LOCAL request.jwt.claims = '${E}'`), await e.query(`SELECT set_config('request.jwt.claim.sub', '${h}', true)`), a.length === 1)
|
|
1159
|
+
await e.query(`SET LOCAL ROLE ${a[0]}`);
|
|
1160
|
+
else {
|
|
1161
|
+
const v = `supaforge_session_${Math.random().toString(36).substring(7)}`;
|
|
1162
|
+
await e.query(`CREATE ROLE ${v} NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT`);
|
|
1163
|
+
for (const O of a)
|
|
1164
|
+
await e.query(`GRANT ${O} TO ${v}`);
|
|
1165
|
+
await e.query(`SET LOCAL ROLE ${v}`);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
const l = await e.query(i, t);
|
|
1169
|
+
if (await e.query("COMMIT"), Array.isArray(l) && l.length > 0 && Array.isArray(l[0]))
|
|
1170
|
+
return l[0];
|
|
1171
|
+
const s = l;
|
|
1172
|
+
return s != null && s.rows ? s.rows : Array.isArray(l) ? l : [];
|
|
1173
|
+
} catch (l) {
|
|
1174
|
+
throw await e.query("ROLLBACK"), l;
|
|
1175
|
+
} finally {
|
|
1176
|
+
await e.query("RESET ROLE");
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
async function et(e) {
|
|
1180
|
+
const { outputDir: r, dbConfig: n } = e;
|
|
1181
|
+
if (!g.existsSync(r)) {
|
|
1182
|
+
console.warn(y.yellow(`Migration directory not found: ${r}`));
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
const i = g.readdirSync(r).filter((a) => a.endsWith("_sec.sql")).sort((a, o) => a.localeCompare(o));
|
|
1186
|
+
if (i.length === 0) {
|
|
1187
|
+
console.info(y.blue("No migrations found to apply."));
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
console.log(y.cyan("Applying migrations..."));
|
|
1191
|
+
const t = new $e(n);
|
|
1192
|
+
await t.connect();
|
|
1193
|
+
try {
|
|
1194
|
+
for (const a of i) {
|
|
1195
|
+
const o = C.join(r, a);
|
|
1196
|
+
console.log(y.gray(`Applying ${a}...`));
|
|
1197
|
+
const l = g.readFileSync(o, "utf8");
|
|
1198
|
+
await t.query(l);
|
|
1199
|
+
}
|
|
1200
|
+
console.log(y.green(`
|
|
1201
|
+
Successfully applied ${String(i.length)} migration(s).`));
|
|
1202
|
+
} catch (a) {
|
|
1203
|
+
const o = a instanceof Error ? a.message : String(a);
|
|
1204
|
+
throw console.error(y.red(`
|
|
1205
|
+
Migration Execution Fault: ${o}`)), a;
|
|
1206
|
+
} finally {
|
|
1207
|
+
await t.end();
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
async function rt(e) {
|
|
1211
|
+
const { entityPath: r, outputDir: n, dbConfig: i } = e, t = C.resolve(r);
|
|
1212
|
+
console.log(y.cyan("Generating documentation..."));
|
|
1213
|
+
const a = await Le(t);
|
|
1214
|
+
if (a.length === 0) {
|
|
1215
|
+
console.info(y.yellow(`No entities found at ${t}`));
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
const o = new pe({
|
|
1219
|
+
type: "postgres",
|
|
1220
|
+
...i,
|
|
1221
|
+
username: i.user,
|
|
1222
|
+
synchronize: !1,
|
|
1223
|
+
entities: a,
|
|
1224
|
+
logging: !1
|
|
1225
|
+
});
|
|
1226
|
+
await o.initialize();
|
|
1227
|
+
try {
|
|
1228
|
+
const l = e.rls !== !1, s = e.cls !== !1, f = {
|
|
1229
|
+
documentation: `
|
|
1230
|
+
Supaforge Documentation and Rules:
|
|
1231
|
+
|
|
1232
|
+
1. PROHIBITED: SELECT (*) USAGE
|
|
1233
|
+
- SELECT (*) is strictly forbidden across the framework.
|
|
1234
|
+
- Reason: Column Level Security (CLS) revokes all public access by default. Accessing an unauthorized column triggers a Database Error.
|
|
1235
|
+
- Requirement: You must explicitly specify columns in your queries (e.g., SELECT id, name).
|
|
1236
|
+
|
|
1237
|
+
2. RLS (Row Level Security) Status: ${l ? "ACTIVE" : "PASSIVE"}
|
|
1238
|
+
- ${l ? "ACTIVE: PostgreSQL filters every row based on JWT claims (role, sub/id). Users only see authorized data." : "PASSIVE: The table is open to all roles with table-level access. HIGH SECURITY RISK."}
|
|
1239
|
+
|
|
1240
|
+
3. CLS (Column Level Security) Status: ${s ? "ACTIVE" : "PASSIVE"}
|
|
1241
|
+
- ${s ? "ACTIVE: Operates on a 'Zero-Trust' model. All access is revoked, then selectively granted via @CLS tags found in the 'columns' section." : "PASSIVE: Standard PostgreSQL column permissions apply."}
|
|
1242
|
+
|
|
1243
|
+
4. JSON Attributes Explanation:
|
|
1244
|
+
- 'columns': Reflects TypeORM metadata and @cls rules (Role-based permissions).
|
|
1245
|
+
- 'rls': Lists @rls rules with their SQL 'USING' or 'CHECK' expressions.
|
|
1246
|
+
- 'runSql': Displays custom SQL for Triggers, Functions, or Hooks defined via @runSql.
|
|
1247
|
+
- 'securitySql': The final, raw PostgreSQL code generated to implement the above security posture.
|
|
1248
|
+
`.trim(),
|
|
1249
|
+
entities: [],
|
|
1250
|
+
generatedAt: "Deterministic output for stability"
|
|
1251
|
+
};
|
|
1252
|
+
for (const d of o.entityMetadatas) {
|
|
1253
|
+
if (typeof d.target == "string") continue;
|
|
1254
|
+
const E = d.target, h = _.isSecurityEnabled(E), v = _.getRLS(E), O = _.getCLS(E), A = _.getCustomSql(E), P = {
|
|
1255
|
+
entityName: d.name,
|
|
1256
|
+
tableName: d.tableName,
|
|
1257
|
+
isSecurityEnabled: h,
|
|
1258
|
+
columns: [],
|
|
1259
|
+
rls: [],
|
|
1260
|
+
runSql: [],
|
|
1261
|
+
checks: d.checks.map((m) => ({ name: m.name || "", expression: m.expression || "" })),
|
|
1262
|
+
securitySql: ""
|
|
1263
|
+
// Will be calculated below
|
|
1264
|
+
}, Fe = {
|
|
1265
|
+
tableName: d.tableName,
|
|
1266
|
+
entityName: d.name,
|
|
1267
|
+
policies: v,
|
|
1268
|
+
columns: O.map((m) => {
|
|
1269
|
+
const T = d.columns.find((b) => b.propertyName === m.propertyKey);
|
|
1270
|
+
if (T) return { ...m, databaseName: T.databaseName };
|
|
1271
|
+
const U = d.relations.find((b) => b.propertyName === m.propertyKey);
|
|
1272
|
+
return U && U.joinColumns.length > 0 ? { ...m, databaseName: U.joinColumns[0].databaseName } : { ...m, databaseName: m.propertyKey };
|
|
1273
|
+
}),
|
|
1274
|
+
customSql: A,
|
|
1275
|
+
isSecurityEnabled: h
|
|
1276
|
+
};
|
|
1277
|
+
P.securitySql = ye([Fe], e);
|
|
1278
|
+
for (const m of d.columns) {
|
|
1279
|
+
const T = O.find((b) => b.propertyKey === m.propertyName), U = {
|
|
1280
|
+
name: m.propertyName,
|
|
1281
|
+
databaseName: m.databaseName,
|
|
1282
|
+
type: String(m.type),
|
|
1283
|
+
isText: m.type === "text" || m.type === String || typeof m.type == "string" && m.type.toLowerCase().includes("char"),
|
|
1284
|
+
length: m.length,
|
|
1285
|
+
isUnique: d.uniques.some((b) => b.columns.includes(m)),
|
|
1286
|
+
isNullable: m.isNullable,
|
|
1287
|
+
isPrimary: m.isPrimary,
|
|
1288
|
+
cls: T ? T.rules : []
|
|
1289
|
+
};
|
|
1290
|
+
P.columns.push(U);
|
|
1291
|
+
}
|
|
1292
|
+
for (const m of v) {
|
|
1293
|
+
const T = m.definition();
|
|
1294
|
+
P.rls.push({
|
|
1295
|
+
name: m.name,
|
|
1296
|
+
crud: m.crud,
|
|
1297
|
+
role: T.role,
|
|
1298
|
+
expression: T.expression
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
for (const m of A)
|
|
1302
|
+
P.runSql.push({
|
|
1303
|
+
name: m.name,
|
|
1304
|
+
sql: m.definition()
|
|
1305
|
+
});
|
|
1306
|
+
f.entities.push(P);
|
|
1307
|
+
}
|
|
1308
|
+
g.existsSync(n) || g.mkdirSync(n, { recursive: !0 });
|
|
1309
|
+
const p = C.join(n, "supaforge-docs.yaml"), c = Un(f, {
|
|
1310
|
+
noRefs: !0,
|
|
1311
|
+
lineWidth: -1,
|
|
1312
|
+
// No line wrap to keep SQL readable
|
|
1313
|
+
styles: {
|
|
1314
|
+
str: "folded"
|
|
1315
|
+
// Better for multi-line SQL
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
g.writeFileSync(p, c), console.log(y.green("Documentation generated successfully:")), console.log(y.gray(` YAML -> ${p}`));
|
|
1319
|
+
} finally {
|
|
1320
|
+
await o.destroy();
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
function nt(e = process.argv) {
|
|
1324
|
+
const r = e, n = () => {
|
|
1325
|
+
const a = r.indexOf("--name");
|
|
1326
|
+
return a > -1 && r[a + 1] ? r[a + 1] : void 0;
|
|
1327
|
+
}, i = r.includes("--sync") || r.includes("--temp");
|
|
1328
|
+
return {
|
|
1329
|
+
apply: r.includes("--apply"),
|
|
1330
|
+
syncSchema: i,
|
|
1331
|
+
migrationName: n()
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
const fe = ["c", "r", "u", "d"], tt = I.string().transform((e) => {
|
|
1335
|
+
const n = e.toLowerCase().trim().split(""), i = n.filter((t) => !fe.includes(t));
|
|
1336
|
+
if (i.length > 0)
|
|
1337
|
+
throw new Error(`Invalid permission flag(s): ${i.join(", ")}. Allowed flags: ${fe.join(", ")}.`);
|
|
1338
|
+
return [...new Set(n)];
|
|
1339
|
+
}), it = I.object({
|
|
1340
|
+
host: I.string().optional().default("localhost"),
|
|
1341
|
+
port: I.number().int().optional().default(5432),
|
|
1342
|
+
user: I.string().optional().default("postgres"),
|
|
1343
|
+
password: I.string().optional().default("postgres"),
|
|
1344
|
+
database: I.string().optional().default("postgres")
|
|
1345
|
+
});
|
|
1346
|
+
export {
|
|
1347
|
+
fe as CRUD_OPS,
|
|
1348
|
+
it as DbConfigSchema,
|
|
1349
|
+
tt as PermissionsSchema,
|
|
1350
|
+
et as applyGeneratedMigrations,
|
|
1351
|
+
ge as buildMigrationFile,
|
|
1352
|
+
ye as buildSecuritySql,
|
|
1353
|
+
Vn as cls,
|
|
1354
|
+
Zn as createMigrationTemplate,
|
|
1355
|
+
nt as extractCliOptions,
|
|
1356
|
+
rt as generateDocumentation,
|
|
1357
|
+
Yn as introspectEntities,
|
|
1358
|
+
_ as registry,
|
|
1359
|
+
Wn as rls,
|
|
1360
|
+
Jn as runAsRole,
|
|
1361
|
+
zn as runSql,
|
|
1362
|
+
Xn as runSupaforge,
|
|
1363
|
+
Qn as security
|
|
1364
|
+
};
|