permdock 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +268 -1
- package/dist/a2a/index.d.ts +178 -0
- package/dist/a2a/index.js +271 -0
- package/dist/ai-sdk/index.d.ts +74 -0
- package/dist/ai-sdk/index.js +137 -0
- package/dist/approval-required-TzNB9oQA.js +6 -0
- package/dist/approvals/index.d.ts +3 -0
- package/dist/approvals/index.js +4 -0
- package/dist/approvals-DaxY-Bdg.js +218 -0
- package/dist/approvers-aH0PJkmf.js +20 -0
- package/dist/arazzo-CTeVuXr5.js +70 -0
- package/dist/arazzo-aoTkqYsJ.js +54 -0
- package/dist/authzen/index.d.ts +48 -0
- package/dist/authzen/index.js +336 -0
- package/dist/better-auth/index.d.ts +92 -0
- package/dist/better-auth/index.js +324 -0
- package/dist/budget-JqcRqyhK.d.ts +11 -0
- package/dist/budget-NbEtbJC_.js +11 -0
- package/dist/capability-B68OFnZx.js +171 -0
- package/dist/capability-BDG_nkxt.d.ts +99 -0
- package/dist/catalog/index.d.ts +12 -0
- package/dist/catalog/index.js +2 -0
- package/dist/catalog-B0E6bggc.js +48 -0
- package/dist/catalog-H-vFGwWK.js +55 -0
- package/dist/catalog-doc-BSo_Q_-6.js +298 -0
- package/dist/catalog-idsHc0vo.js +2 -0
- package/dist/catalog-path-CnI0XTFK.js +12 -0
- package/dist/claude-agent/index.d.ts +81 -0
- package/dist/claude-agent/index.js +83 -0
- package/dist/clerk/index.d.ts +56 -0
- package/dist/clerk/index.js +280 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +20 -0
- package/dist/cli/index.d.ts +46 -0
- package/dist/cli/index.js +5 -0
- package/dist/cloud/index.d.ts +91 -0
- package/dist/cloud/index.js +390 -0
- package/dist/cloud-BNQTrmrr.js +50 -0
- package/dist/cloud-Cuxr6Czw.js +117 -0
- package/dist/collect-B7_TIfmg.js +49 -0
- package/dist/collect-O-tOtbnk.js +350 -0
- package/dist/collect-fRPAQIWb.js +2 -0
- package/dist/commands-BMh_Etm2.js +93 -0
- package/dist/compact-y6vfu2_f.js +19 -0
- package/dist/compare-pfyVnBjE.js +12 -0
- package/dist/compile-CQbvyIBr.d.ts +30 -0
- package/dist/compile-D22iwvuV.js +558 -0
- package/dist/config-BPYmjTOp.js +26 -0
- package/dist/connection-JvqwHODC.js +194 -0
- package/dist/context-CKEAabd7.js +73 -0
- package/dist/context-gtAwAILx.js +6 -0
- package/dist/convex/index.d.ts +40 -0
- package/dist/convex/index.js +55 -0
- package/dist/create-BKF3dgFk.d.ts +162 -0
- package/dist/create-CSkhDU9T.js +222 -0
- package/dist/credential-B_rkUNlY.js +326 -0
- package/dist/credentials-BgRX3WEg.js +268 -0
- package/dist/describe-Bt1YD5uS.js +99 -0
- package/dist/describe-DernyItf.d.ts +37 -0
- package/dist/diff-BUzf5Poi.js +48 -0
- package/dist/diff-x5Il8LVa.js +418 -0
- package/dist/digest-B3kc_PgQ.d.ts +19 -0
- package/dist/digest-BI-6aa6d.js +27 -0
- package/dist/doctor-BGle8Gqi.js +1314 -0
- package/dist/doctor-Bqo6FwUa.js +53 -0
- package/dist/drizzle/index.d.ts +72 -0
- package/dist/drizzle/index.js +160 -0
- package/dist/duration-xK2jGFVc.js +25 -0
- package/dist/elysia/index.d.ts +71 -0
- package/dist/elysia/index.js +103 -0
- package/dist/errors-DSMnAVNa.js +43 -0
- package/dist/errors-DbZ1YOnb.d.ts +138 -0
- package/dist/errors-Iy71s7Oj.js +177 -0
- package/dist/errors-m3u9TmDu.js +27 -0
- package/dist/evaluations-DsAU9ppl.js +479 -0
- package/dist/eve/index.d.ts +95 -0
- package/dist/eve/index.js +181 -0
- package/dist/express/index.d.ts +46 -0
- package/dist/express/index.js +108 -0
- package/dist/fastify/index.d.ts +56 -0
- package/dist/fastify/index.js +141 -0
- package/dist/files-B_wAGYmt.js +121 -0
- package/dist/fixtures-Cvaw0gDG.js +64 -0
- package/dist/freeze-y1_jQL4v.js +31 -0
- package/dist/from-snapshot-BMGnhmgv.js +552 -0
- package/dist/generate-CH7ThJ14.js +173 -0
- package/dist/grantee-Bv04_Vzf.js +521 -0
- package/dist/headers-B5RRv3Xm.js +6 -0
- package/dist/headers-C8SHQccD.d.ts +6 -0
- package/dist/helpers-DnSOrhB9.js +682 -0
- package/dist/hono/index.d.ts +70 -0
- package/dist/hono/index.js +131 -0
- package/dist/hosted-BwKQ1BTA.js +265 -0
- package/dist/http-DPuDaChb.d.ts +13 -0
- package/dist/http-GgVApX1k.js +111 -0
- package/dist/index-CltcQ4Bf.d.ts +138 -0
- package/dist/index-LF_hS-yn.d.ts +177 -0
- package/dist/index-fG6NSXlc.d.ts +9 -0
- package/dist/index-xIxJLwOQ.d.ts +415 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +21 -0
- package/dist/jwt/index.d.ts +87 -0
- package/dist/jwt/index.js +571 -0
- package/dist/kernel-YOGCWNLf.js +211 -0
- package/dist/kysely/index.d.ts +77 -0
- package/dist/kysely/index.js +129 -0
- package/dist/load-BZ24CpZP.js +69 -0
- package/dist/load-QOOm1z70.js +2 -0
- package/dist/load-jose-BL6LH4bL.js +11 -0
- package/dist/lru-8q4WZjBV.js +28 -0
- package/dist/manifest-DDQbC6K0.d.ts +118 -0
- package/dist/map-DowSO96j.js +158 -0
- package/dist/map-claims-B_6I1Rn-.js +360 -0
- package/dist/map-error-RJ3ZsUyA.js +16 -0
- package/dist/markers-B0hYLvMD.js +60 -0
- package/dist/may-use-CnFEjVEp.js +37 -0
- package/dist/mcp/index.d.ts +127 -0
- package/dist/mcp/index.js +563 -0
- package/dist/nest/index.d.ts +80 -0
- package/dist/nest/index.js +270 -0
- package/dist/next/client.d.ts +24 -0
- package/dist/next/client.js +31 -0
- package/dist/next/index.d.ts +110 -0
- package/dist/next/index.js +195 -0
- package/dist/next/plugin.d.ts +14 -0
- package/dist/next/plugin.js +2 -0
- package/dist/node/index.d.ts +43 -0
- package/dist/node/index.js +66 -0
- package/dist/openai/index.d.ts +71 -0
- package/dist/openai/index.js +105 -0
- package/dist/openapi/index.d.ts +93 -0
- package/dist/openapi/index.js +3 -0
- package/dist/openapi-CwePaF7C.js +164 -0
- package/dist/openapi-DWD0Uc_4.js +250 -0
- package/dist/openapi-DcqM8nU7.js +306 -0
- package/dist/openapi-import-BWRUNNeW.js +5959 -0
- package/dist/openapi-schema-D8j_T9tO.js +6902 -0
- package/dist/orpc/index.d.ts +64 -0
- package/dist/orpc/index.js +188 -0
- package/dist/otel/index.d.ts +13 -0
- package/dist/otel/index.js +202 -0
- package/dist/package-root-zGkxO3oN.js +30 -0
- package/dist/parse-DPfIvFMU.js +135 -0
- package/dist/pdp/index.d.ts +22 -0
- package/dist/pdp/index.js +795 -0
- package/dist/peer-BOr_kJE1.js +31 -0
- package/dist/permdock-yoZ7EjxX.js +2956 -0
- package/dist/permissions-B4apnahQ.d.ts +185 -0
- package/dist/permissions-B8vCg_bI.d.ts +52 -0
- package/dist/permissions-CofRqesP.js +142 -0
- package/dist/permissions-DC7GROPA.js +600 -0
- package/dist/pg-4GJWDUxG.js +953 -0
- package/dist/pins-CqE1jZuF.js +12 -0
- package/dist/plugin-4gr7IxFJ.js +65 -0
- package/dist/policy-ANp36PnI.js +971 -0
- package/dist/policy-CInmNGkM.d.ts +1959 -0
- package/dist/policy-Cq2fB8Q5.d.ts +20 -0
- package/dist/prisma/index.d.ts +135 -0
- package/dist/prisma/index.js +430 -0
- package/dist/problem-Cgp9-KZA.js +226 -0
- package/dist/prompt-CXYhLfsS.js +32 -0
- package/dist/protected-B4K3BKoX.js +138 -0
- package/dist/protected-BuPAycJT.d.ts +26 -0
- package/dist/protected-wY7nXhY9.d.ts +23 -0
- package/dist/provider-_wx46HpB.js +48 -0
- package/dist/provider-wTAUda2v.d.ts +6 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.js +6 -0
- package/dist/react/provider-client.d.ts +2 -0
- package/dist/react/provider-client.js +3 -0
- package/dist/react-native/index.d.ts +42 -0
- package/dist/react-native/index.js +174 -0
- package/dist/refs-ChLSxbST.js +90 -0
- package/dist/relations-r4soIFZB.js +426 -0
- package/dist/revocations-Cy06JNx2.d.ts +21 -0
- package/dist/rls-BOFU3chG.js +233 -0
- package/dist/rls-CJVja9Ww.js +2119 -0
- package/dist/rls-graph-DxQ39PJj.js +371 -0
- package/dist/rls-helpers-BxRuif0l.js +1346 -0
- package/dist/rls-import-CXV6LBlS.js +942 -0
- package/dist/rls-migrate-DrFPbf8p.js +366 -0
- package/dist/row-check-BajTgQZ-.d.ts +43 -0
- package/dist/run-CJ6UvS3a.js +155 -0
- package/dist/runtime-DP9ttFh1.js +27 -0
- package/dist/saas-BRrZzJkM.js +1193 -0
- package/dist/schema-P8yoma__.js +296 -0
- package/dist/scim/index.d.ts +2 -0
- package/dist/scim/index.js +2 -0
- package/dist/scim-9NFa0XVZ.js +1445 -0
- package/dist/scopes-cKVp_WTw.js +212 -0
- package/dist/server/index.d.ts +123 -0
- package/dist/server/index.js +8 -0
- package/dist/sha256-BO0swRXL.js +150 -0
- package/dist/sink-Bd9PSyfq.js +141 -0
- package/dist/sink-Cfr9-7YC.d.ts +104 -0
- package/dist/skills-C_lpV4Jx.js +50 -0
- package/dist/skills-Dx3QLnMY.js +110 -0
- package/dist/snapshot-DE8dE_hz.js +1051 -0
- package/dist/solid/index.d.ts +63 -0
- package/dist/solid/index.js +197 -0
- package/dist/source-DoBBYJi2.js +6 -0
- package/dist/sources-DOpW5Ila.d.ts +347 -0
- package/dist/sources-DVHM3Mwq.js +284 -0
- package/dist/sql-Bll1d7y0.js +22 -0
- package/dist/src-CTNT-PBW.js +430 -0
- package/dist/ssf/index.d.ts +3 -0
- package/dist/ssf/index.js +622 -0
- package/dist/store-Bq90395i.d.ts +27 -0
- package/dist/store-C6hFW6ta.js +508 -0
- package/dist/stores-CkG2HrSg.js +140 -0
- package/dist/stores-CvOnu_2T.d.ts +41 -0
- package/dist/stream-BhMfZOwr.d.ts +12 -0
- package/dist/stream-Q_xlB6Ko.js +52 -0
- package/dist/style-CTm1AXDT.js +22 -0
- package/dist/subject-C6dLxqHU.js +24 -0
- package/dist/subject-settings-xt7V845g.js +82 -0
- package/dist/supabase/index.d.ts +67 -0
- package/dist/supabase/index.js +4 -0
- package/dist/supabase/middleware.d.ts +77 -0
- package/dist/supabase/middleware.js +68 -0
- package/dist/supabase-D8UlBA7Z.js +83 -0
- package/dist/supabase-DTxGtYdi.js +796 -0
- package/dist/supabase-hook-DW-xP4hU.js +2 -0
- package/dist/supabase-hook-D_OqGb_V.js +1528 -0
- package/dist/svelte/Protected.svelte +34 -0
- package/dist/svelte/index.d.ts +10 -0
- package/dist/svelte/index.js +53 -0
- package/dist/svelte/runtime.d.ts +6 -0
- package/dist/svelte/runtime.js +3 -0
- package/dist/svelte/source.d.ts +10 -0
- package/dist/svelte/source.js +8 -0
- package/dist/terminal/index.d.ts +171 -0
- package/dist/terminal/index.js +821 -0
- package/dist/testing/index.d.ts +656 -0
- package/dist/testing/index.js +3208 -0
- package/dist/testing/saas/index.d.ts +194 -0
- package/dist/testing/saas/index.js +3 -0
- package/dist/testing/saas/permissions.d.ts +2 -0
- package/dist/testing/saas/permissions.js +2 -0
- package/dist/text-diff-BdkkYSbi.js +15 -0
- package/dist/thenable-okc2xDsj.js +10 -0
- package/dist/timeout-D51niuQP.js +8 -0
- package/dist/trpc/index.d.ts +80 -0
- package/dist/trpc/index.js +205 -0
- package/dist/types-B8w5PFtS.d.ts +141 -0
- package/dist/types-B9dmiiab.d.ts +66 -0
- package/dist/types-BBK-exvJ.d.ts +177 -0
- package/dist/types-BvBk1wgn.d.ts +118 -0
- package/dist/types-CxquUByI.d.ts +9 -0
- package/dist/types-D6Z6-rKJ.d.ts +312 -0
- package/dist/types-DbWdEfcm.d.ts +87 -0
- package/dist/types-bva3i4Gf.d.ts +98 -0
- package/dist/types-i4BAOvdb.d.ts +97 -0
- package/dist/unplugin/index.d.ts +7 -0
- package/dist/unplugin/index.js +30 -0
- package/dist/usage-1ozMubLY.js +42 -0
- package/dist/usage-CUnK6Ou9.js +530 -0
- package/dist/usage-PyEor6GA.js +2 -0
- package/dist/validity-D0uRmJKJ.js +224 -0
- package/dist/verifier-B90agnhl.js +461 -0
- package/dist/version-CnSh33Fj.js +16 -0
- package/dist/vocabulary-Dk0fs-Jk.d.ts +56 -0
- package/dist/vue/index.d.ts +57 -0
- package/dist/vue/index.js +203 -0
- package/dist/webmcp/index.d.ts +75 -0
- package/dist/webmcp/index.js +313 -0
- package/package.json +423 -4
- package/rulesets/permdock.yaml +29 -0
- package/schemas/catalog-v1.json +507 -0
- package/schemas/openapi/oas-3.1.json +1298 -0
- package/schemas/openapi/oas-3.2.json +1516 -0
- package/schemas/openapi/overlay-1.1.json +79 -0
- package/schemas/supabase-claims-v1.json +139 -0
- package/schemas/supabase-manifest-v1.json +217 -0
- package/skills/permdock/SKILL.md +66 -0
- package/skills/permdock-agents/SKILL.md +77 -0
- package/skills/permdock-agents/references/runtimes.md +211 -0
- package/skills/permdock-approvals/SKILL.md +80 -0
- package/skills/permdock-approvals/references/stores-and-resume.md +83 -0
- package/skills/permdock-audit/SKILL.md +67 -0
- package/skills/permdock-credentials/SKILL.md +55 -0
- package/skills/permdock-credentials/references/tokens-keys-links.md +127 -0
- package/skills/permdock-data/SKILL.md +57 -0
- package/skills/permdock-data/references/queries-and-rls.md +54 -0
- package/skills/permdock-data/references/relationships.md +65 -0
- package/skills/permdock-tenancy/SKILL.md +77 -0
- package/skills/permdock-tenancy/references/ownership-and-custom-roles.md +83 -0
- package/skills/permdock-wire/SKILL.md +116 -0
- package/skills/permdock-wire/references/adapters.md +480 -0
- package/skills/permdock-wire/references/policy-options.md +43 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { existsSync, globSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { basename, extname, join, relative, resolve } from "node:path";
|
|
3
|
+
//#region src/cli/files.ts
|
|
4
|
+
const SOURCE_EXT = /* @__PURE__ */ new Set([
|
|
5
|
+
".ts",
|
|
6
|
+
".tsx",
|
|
7
|
+
".js",
|
|
8
|
+
".jsx",
|
|
9
|
+
".mts",
|
|
10
|
+
".cts"
|
|
11
|
+
]);
|
|
12
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
13
|
+
"node_modules",
|
|
14
|
+
"dist",
|
|
15
|
+
".next",
|
|
16
|
+
".turbo",
|
|
17
|
+
"coverage",
|
|
18
|
+
".git"
|
|
19
|
+
]);
|
|
20
|
+
const PACKAGE_SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git"]);
|
|
21
|
+
function listSourceFiles(cwd, srcPath) {
|
|
22
|
+
const out = /* @__PURE__ */ new Set();
|
|
23
|
+
for (const entry of srcPath) {
|
|
24
|
+
if (/[*?[{]/u.test(entry)) {
|
|
25
|
+
collectGlob(cwd, entry, out);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
collectRoot(resolve(cwd, entry), out, skipDirsFor(entry));
|
|
29
|
+
}
|
|
30
|
+
const byRealPath = /* @__PURE__ */ new Map();
|
|
31
|
+
for (const file of [...out].toSorted()) {
|
|
32
|
+
const real = realPath(file);
|
|
33
|
+
if (!byRealPath.has(real)) byRealPath.set(real, file);
|
|
34
|
+
}
|
|
35
|
+
return [...byRealPath.values()].toSorted();
|
|
36
|
+
}
|
|
37
|
+
function segments(path) {
|
|
38
|
+
return path.split(/[\\/]/u).filter((part) => part !== "" && part !== ".");
|
|
39
|
+
}
|
|
40
|
+
/** Installed packages often ship only `dist`; their own dependencies are never walked. */
|
|
41
|
+
function skipDirsFor(path) {
|
|
42
|
+
return segments(path).includes("node_modules") ? PACKAGE_SKIP_DIRS : SKIP_DIRS;
|
|
43
|
+
}
|
|
44
|
+
function realPath(file) {
|
|
45
|
+
try {
|
|
46
|
+
return realpathSync(file);
|
|
47
|
+
} catch {
|
|
48
|
+
return file;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function collectGlob(cwd, pattern, out) {
|
|
52
|
+
const literal = segments(pattern);
|
|
53
|
+
const matches = globSync(pattern, {
|
|
54
|
+
cwd,
|
|
55
|
+
exclude: (path) => {
|
|
56
|
+
const parts = segments(path);
|
|
57
|
+
const name = basename(path);
|
|
58
|
+
return SKIP_DIRS.has(name) && literal[parts.length - 1] !== name;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
for (const match of matches) collectRoot(resolve(cwd, match), out, skipDirsFor(match));
|
|
62
|
+
}
|
|
63
|
+
function collectRoot(root, out, skip) {
|
|
64
|
+
if (!existsSync(root)) return;
|
|
65
|
+
if (statSync(root).isFile()) {
|
|
66
|
+
if (SOURCE_EXT.has(extname(root))) out.add(root);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
walkDir(root, out, skip);
|
|
70
|
+
}
|
|
71
|
+
function walkDir(dir, out, skip) {
|
|
72
|
+
for (const name of readdirSync(dir)) {
|
|
73
|
+
if (name.startsWith(".") && name !== ".agents") continue;
|
|
74
|
+
if (skip.has(name)) continue;
|
|
75
|
+
const full = join(dir, name);
|
|
76
|
+
const stats = statSync(full, { throwIfNoEntry: false });
|
|
77
|
+
if (stats === void 0) continue;
|
|
78
|
+
if (stats.isDirectory()) {
|
|
79
|
+
walkDir(full, out, skip);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (SOURCE_EXT.has(extname(name)) && !name.endsWith(".generated.ts")) out.add(full);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The `.sql` files under each entry: a glob, a file, or a directory searched
|
|
87
|
+
* recursively. `order: 'entry'` keeps each entry's matches together in entry
|
|
88
|
+
* order (how `supabase db diff` reads `schema_paths`); the default sorts all paths.
|
|
89
|
+
*/
|
|
90
|
+
function sqlFiles(cwd, entries, options = {}) {
|
|
91
|
+
const seen = /* @__PURE__ */ new Set();
|
|
92
|
+
const ordered = [];
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
const abs = resolve(cwd, entry);
|
|
95
|
+
const isGlob = /[*?[{]/u.test(entry);
|
|
96
|
+
if (!isGlob && statSync(abs, { throwIfNoEntry: false })?.isFile()) {
|
|
97
|
+
if (!seen.has(abs)) {
|
|
98
|
+
seen.add(abs);
|
|
99
|
+
ordered.push(abs);
|
|
100
|
+
}
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const pattern = isGlob ? entry : `${entry}/**/*.sql`;
|
|
104
|
+
for (const match of globSync(pattern, { cwd }).toSorted()) {
|
|
105
|
+
const path = resolve(cwd, match);
|
|
106
|
+
if (path.endsWith(".sql") && !seen.has(path)) {
|
|
107
|
+
seen.add(path);
|
|
108
|
+
ordered.push(path);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return options.order === "entry" ? ordered : ordered.toSorted();
|
|
113
|
+
}
|
|
114
|
+
function rel(cwd, abs) {
|
|
115
|
+
return relative(cwd, abs).split("\\").join("/");
|
|
116
|
+
}
|
|
117
|
+
function defaultSrcPath() {
|
|
118
|
+
return ["./src"];
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
export { sqlFiles as i, listSourceFiles as n, rel as r, defaultSrcPath as t };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { a as loadModule, o as pickNamed } from "./load-BZ24CpZP.js";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
//#region src/cli/fixtures.ts
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function asFixtures(value) {
|
|
9
|
+
const list = Array.isArray(value) ? value : isRecord(value) && Array.isArray(value["fixtures"]) ? value["fixtures"] : void 0;
|
|
10
|
+
if (list === void 0) throw new Error("PermDock CLI: fixtures must be an array or { fixtures }");
|
|
11
|
+
return list.map((item, index) => {
|
|
12
|
+
if (!isRecord(item) || !isRecord(item["subject"]) || item["row"] === void 0) throw new Error(`PermDock CLI: fixture ${index} needs subject and row`);
|
|
13
|
+
if (typeof item["action"] !== "string") throw new TypeError(`PermDock CLI: fixture ${index} needs action`);
|
|
14
|
+
if (typeof item["subject"]["id"] !== "string") throw new TypeError(`PermDock CLI: fixture ${index} subject needs id`);
|
|
15
|
+
const memberships = item["subject"]["memberships"];
|
|
16
|
+
if (memberships !== void 0 && !Array.isArray(memberships)) throw new Error(`PermDock CLI: fixture ${index} subject.memberships must be an array`);
|
|
17
|
+
const tenant = item["subject"]["tenant"];
|
|
18
|
+
if (tenant !== void 0 && typeof tenant !== "string") throw new Error(`PermDock CLI: fixture ${index} subject.tenant must be a string`);
|
|
19
|
+
return item;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function asCustomRoles(value) {
|
|
23
|
+
if (!isRecord(value) || value["customRoles"] === void 0) return [];
|
|
24
|
+
if (!Array.isArray(value["customRoles"])) throw new TypeError("PermDock CLI: fixtures customRoles must be an array");
|
|
25
|
+
return value["customRoles"];
|
|
26
|
+
}
|
|
27
|
+
/** A `.json` file or a module exporting `fixtures` (or default) and optionally `customRoles`. */
|
|
28
|
+
async function loadFixtures(cwd, path) {
|
|
29
|
+
const abs = resolve(cwd, path);
|
|
30
|
+
if (!existsSync(abs)) throw new Error(`PermDock CLI: fixtures not found: ${path}`);
|
|
31
|
+
if (abs.endsWith(".json")) {
|
|
32
|
+
const parsed = JSON.parse(readFileSync(abs, "utf8"));
|
|
33
|
+
return {
|
|
34
|
+
fixtures: asFixtures(parsed),
|
|
35
|
+
customRoles: asCustomRoles(parsed)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const mod = await loadModule(abs);
|
|
39
|
+
return {
|
|
40
|
+
fixtures: asFixtures(pickNamed(mod, ["fixtures", "default"])),
|
|
41
|
+
customRoles: asCustomRoles(mod)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** The fixture subject as a `Subject`: a principal with no actor and an empty context. */
|
|
45
|
+
function fixtureSubject(fixture) {
|
|
46
|
+
return {
|
|
47
|
+
principal: {
|
|
48
|
+
id: fixture.id,
|
|
49
|
+
roles: fixture.roles ?? [],
|
|
50
|
+
...fixture.tenant === void 0 ? {} : { tenant: fixture.tenant },
|
|
51
|
+
memberships: fixture.memberships ?? []
|
|
52
|
+
},
|
|
53
|
+
context: {}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** The row `can` receives: `{ current, next }` for an instance action with a `newRow`. */
|
|
57
|
+
function fixtureRow(fixture, kind) {
|
|
58
|
+
return fixture.newRow === void 0 || kind === "collection" ? fixture.row : {
|
|
59
|
+
current: fixture.row,
|
|
60
|
+
next: fixture.newRow
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { fixtureSubject as n, loadFixtures as r, fixtureRow as t };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/core/freeze.ts
|
|
2
|
+
function freezeDeep(value) {
|
|
3
|
+
if (value === null || typeof value !== "object") return value;
|
|
4
|
+
if (value instanceof Map || value instanceof Set) {
|
|
5
|
+
Object.freeze(value);
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
if (Object.isFrozen(value)) return value;
|
|
9
|
+
Object.freeze(value);
|
|
10
|
+
if (Array.isArray(value)) {
|
|
11
|
+
for (const item of value) freezeDeep(item);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
for (const key of Object.getOwnPropertyNames(value)) freezeDeep(value[key]);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
function isPlain(value) {
|
|
18
|
+
const proto = Object.getPrototypeOf(value);
|
|
19
|
+
return proto === Object.prototype || proto === null;
|
|
20
|
+
}
|
|
21
|
+
/** A deeply frozen copy of the plain objects and arrays in `value`; the caller's own objects stay writable. */
|
|
22
|
+
function freezeCopy(value) {
|
|
23
|
+
if (value === null || typeof value !== "object") return value;
|
|
24
|
+
if (Array.isArray(value)) return Object.freeze(value.map((item) => freezeCopy(item)));
|
|
25
|
+
if (!isPlain(value)) return value;
|
|
26
|
+
const copy = {};
|
|
27
|
+
for (const key of Object.keys(value)) copy[key] = freezeCopy(value[key]);
|
|
28
|
+
return Object.freeze(copy);
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { freezeDeep as n, freezeCopy as t };
|