drizzle-orm 0.35.3 → 0.36.0-19f042a

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.
Files changed (85) hide show
  1. package/mysql-core/columns/decimal.cjs +12 -7
  2. package/mysql-core/columns/decimal.cjs.map +1 -1
  3. package/mysql-core/columns/decimal.d.cts +3 -1
  4. package/mysql-core/columns/decimal.d.ts +3 -1
  5. package/mysql-core/columns/decimal.js +12 -7
  6. package/mysql-core/columns/decimal.js.map +1 -1
  7. package/mysql-core/columns/double.cjs +7 -3
  8. package/mysql-core/columns/double.cjs.map +1 -1
  9. package/mysql-core/columns/double.d.cts +4 -2
  10. package/mysql-core/columns/double.d.ts +4 -2
  11. package/mysql-core/columns/double.js +7 -3
  12. package/mysql-core/columns/double.js.map +1 -1
  13. package/mysql-core/columns/float.cjs +20 -4
  14. package/mysql-core/columns/float.cjs.map +1 -1
  15. package/mysql-core/columns/float.d.cts +13 -4
  16. package/mysql-core/columns/float.d.ts +13 -4
  17. package/mysql-core/columns/float.js +20 -4
  18. package/mysql-core/columns/float.js.map +1 -1
  19. package/neon/index.cjs +23 -0
  20. package/neon/index.cjs.map +1 -0
  21. package/neon/index.d.cts +1 -0
  22. package/neon/index.d.ts +1 -0
  23. package/neon/index.js +2 -0
  24. package/neon/index.js.map +1 -0
  25. package/neon/rls.cjs +96 -0
  26. package/neon/rls.cjs.map +1 -0
  27. package/neon/rls.d.cts +20 -0
  28. package/neon/rls.d.ts +20 -0
  29. package/neon/rls.js +69 -0
  30. package/neon/rls.js.map +1 -0
  31. package/package.json +127 -51
  32. package/pg-core/index.cjs +4 -0
  33. package/pg-core/index.cjs.map +1 -1
  34. package/pg-core/index.d.cts +2 -0
  35. package/pg-core/index.d.ts +2 -0
  36. package/pg-core/index.js +2 -0
  37. package/pg-core/index.js.map +1 -1
  38. package/pg-core/policies.cjs +58 -0
  39. package/pg-core/policies.cjs.map +1 -0
  40. package/pg-core/policies.d.cts +24 -0
  41. package/pg-core/policies.d.ts +24 -0
  42. package/pg-core/policies.js +33 -0
  43. package/pg-core/policies.js.map +1 -0
  44. package/pg-core/roles.cjs +57 -0
  45. package/pg-core/roles.cjs.map +1 -0
  46. package/pg-core/roles.d.cts +13 -0
  47. package/pg-core/roles.d.ts +13 -0
  48. package/pg-core/roles.js +32 -0
  49. package/pg-core/roles.js.map +1 -0
  50. package/pg-core/table.cjs +13 -2
  51. package/pg-core/table.cjs.map +1 -1
  52. package/pg-core/table.d.cts +25 -3
  53. package/pg-core/table.d.ts +25 -3
  54. package/pg-core/table.js +12 -2
  55. package/pg-core/table.js.map +1 -1
  56. package/pg-core/utils.cjs +10 -2
  57. package/pg-core/utils.cjs.map +1 -1
  58. package/pg-core/utils.d.cts +3 -0
  59. package/pg-core/utils.d.ts +3 -0
  60. package/pg-core/utils.js +10 -2
  61. package/pg-core/utils.js.map +1 -1
  62. package/supabase/index.cjs +23 -0
  63. package/supabase/index.cjs.map +1 -0
  64. package/supabase/index.d.cts +1 -0
  65. package/supabase/index.d.ts +1 -0
  66. package/supabase/index.js +2 -0
  67. package/supabase/index.js.map +1 -0
  68. package/supabase/rls.cjs +76 -0
  69. package/supabase/rls.cjs.map +1 -0
  70. package/supabase/rls.d.cts +197 -0
  71. package/supabase/rls.d.ts +197 -0
  72. package/supabase/rls.js +44 -0
  73. package/supabase/rls.js.map +1 -0
  74. package/table.cjs.map +1 -1
  75. package/table.js.map +1 -1
  76. package/utils.cjs +1 -1
  77. package/utils.cjs.map +1 -1
  78. package/utils.js +1 -1
  79. package/utils.js.map +1 -1
  80. package/version.cjs +2 -2
  81. package/version.cjs.map +1 -1
  82. package/version.d.cts +2 -2
  83. package/version.d.ts +2 -2
  84. package/version.js +2 -2
  85. package/version.js.map +1 -1
package/neon/rls.cjs ADDED
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var rls_exports = {};
20
+ __export(rls_exports, {
21
+ anonymousRole: () => anonymousRole,
22
+ authUid: () => authUid,
23
+ authenticatedRole: () => authenticatedRole,
24
+ crudPolicy: () => crudPolicy
25
+ });
26
+ module.exports = __toCommonJS(rls_exports);
27
+ var import_entity = require("../entity.cjs");
28
+ var import_pg_core = require("../pg-core/index.cjs");
29
+ var import_roles = require("../pg-core/roles.cjs");
30
+ var import_sql = require("../sql/sql.cjs");
31
+ const crudPolicy = (options) => {
32
+ if (options.read === void 0) {
33
+ throw new Error("crudPolicy requires a read policy");
34
+ }
35
+ if (options.modify === void 0) {
36
+ throw new Error("crudPolicy requires a modify policy");
37
+ }
38
+ let read;
39
+ if (options.read === true) {
40
+ read = import_sql.sql`true`;
41
+ } else if (options.read === false) {
42
+ read = import_sql.sql`false`;
43
+ } else if (options.read !== null) {
44
+ read = options.read;
45
+ }
46
+ let modify;
47
+ if (options.modify === true) {
48
+ modify = import_sql.sql`true`;
49
+ } else if (options.modify === false) {
50
+ modify = import_sql.sql`false`;
51
+ } else if (options.modify !== null) {
52
+ modify = options.modify;
53
+ }
54
+ let rolesName = "";
55
+ if (Array.isArray(options.role)) {
56
+ rolesName = options.role.map((it) => {
57
+ return (0, import_entity.is)(it, import_roles.PgRole) ? it.name : it;
58
+ }).join("-");
59
+ } else {
60
+ rolesName = (0, import_entity.is)(options.role, import_roles.PgRole) ? options.role.name : options.role;
61
+ }
62
+ return [
63
+ read && (0, import_pg_core.pgPolicy)(`crud-${rolesName}-policy-select`, {
64
+ for: "select",
65
+ to: options.role,
66
+ using: read
67
+ }),
68
+ modify && (0, import_pg_core.pgPolicy)(`crud-${rolesName}-policy-insert`, {
69
+ for: "insert",
70
+ to: options.role,
71
+ withCheck: modify
72
+ }),
73
+ modify && (0, import_pg_core.pgPolicy)(`crud-${rolesName}-policy-update`, {
74
+ for: "update",
75
+ to: options.role,
76
+ using: modify,
77
+ withCheck: modify
78
+ }),
79
+ modify && (0, import_pg_core.pgPolicy)(`crud-${rolesName}-policy-delete`, {
80
+ for: "delete",
81
+ to: options.role,
82
+ using: modify
83
+ })
84
+ ].filter(Boolean);
85
+ };
86
+ const authenticatedRole = (0, import_roles.pgRole)("authenticated").existing();
87
+ const anonymousRole = (0, import_roles.pgRole)("anonymous").existing();
88
+ const authUid = (userIdColumn) => import_sql.sql`(select auth.user_id() = ${userIdColumn})`;
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ anonymousRole,
92
+ authUid,
93
+ authenticatedRole,
94
+ crudPolicy
95
+ });
96
+ //# sourceMappingURL=rls.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/neon/rls.ts"],"sourcesContent":["import { is } from '~/entity.ts';\nimport { type AnyPgColumn, pgPolicy, type PgPolicyToOption } from '~/pg-core/index.ts';\nimport { PgRole, pgRole } from '~/pg-core/roles.ts';\nimport { type SQL, sql } from '~/sql/sql.ts';\n\n/**\n * Generates a set of PostgreSQL row-level security (RLS) policies for CRUD operations based on the provided options.\n *\n * @param options - An object containing the policy configuration.\n * @param options.role - The PostgreSQL role(s) to apply the policy to. Can be a single `PgRole` instance or an array of `PgRole` instances or role names.\n * @param options.read - The SQL expression or boolean value that defines the read policy. Set to `true` to allow all reads, `false` to deny all reads, or provide a custom SQL expression. Set to `null` to prevent the policy from being generated.\n * @param options.modify - The SQL expression or boolean value that defines the modify (insert, update, delete) policies. Set to `true` to allow all modifications, `false` to deny all modifications, or provide a custom SQL expression. Set to `null` to prevent policies from being generated.\n * @returns An array of PostgreSQL policy definitions, one for each CRUD operation.\n */\nexport const crudPolicy = (options: {\n\trole: PgPolicyToOption;\n\tread: SQL | boolean | null;\n\tmodify: SQL | boolean | null;\n}) => {\n\tif (options.read === undefined) {\n\t\tthrow new Error('crudPolicy requires a read policy');\n\t}\n\n\tif (options.modify === undefined) {\n\t\tthrow new Error('crudPolicy requires a modify policy');\n\t}\n\n\tlet read: SQL | undefined;\n\tif (options.read === true) {\n\t\tread = sql`true`;\n\t} else if (options.read === false) {\n\t\tread = sql`false`;\n\t} else if (options.read !== null) {\n\t\tread = options.read;\n\t}\n\n\tlet modify: SQL | undefined;\n\tif (options.modify === true) {\n\t\tmodify = sql`true`;\n\t} else if (options.modify === false) {\n\t\tmodify = sql`false`;\n\t} else if (options.modify !== null) {\n\t\tmodify = options.modify;\n\t}\n\n\tlet rolesName = '';\n\tif (Array.isArray(options.role)) {\n\t\trolesName = options.role\n\t\t\t.map((it) => {\n\t\t\t\treturn is(it, PgRole) ? it.name : (it as string);\n\t\t\t})\n\t\t\t.join('-');\n\t} else {\n\t\trolesName = is(options.role, PgRole)\n\t\t\t? options.role.name\n\t\t\t: (options.role as string);\n\t}\n\n\treturn [\n\t\tread\n\t\t&& pgPolicy(`crud-${rolesName}-policy-select`, {\n\t\t\tfor: 'select',\n\t\t\tto: options.role,\n\t\t\tusing: read,\n\t\t}),\n\n\t\tmodify\n\t\t&& pgPolicy(`crud-${rolesName}-policy-insert`, {\n\t\t\tfor: 'insert',\n\t\t\tto: options.role,\n\t\t\twithCheck: modify,\n\t\t}),\n\t\tmodify\n\t\t&& pgPolicy(`crud-${rolesName}-policy-update`, {\n\t\t\tfor: 'update',\n\t\t\tto: options.role,\n\t\t\tusing: modify,\n\t\t\twithCheck: modify,\n\t\t}),\n\t\tmodify\n\t\t&& pgPolicy(`crud-${rolesName}-policy-delete`, {\n\t\t\tfor: 'delete',\n\t\t\tto: options.role,\n\t\t\tusing: modify,\n\t\t}),\n\t].filter(Boolean);\n};\n\n// These are default roles that Neon will set up.\nexport const authenticatedRole = pgRole('authenticated').existing();\nexport const anonymousRole = pgRole('anonymous').existing();\n\nexport const authUid = (userIdColumn: AnyPgColumn) => sql`(select auth.user_id() = ${userIdColumn})`;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AACnB,qBAAkE;AAClE,mBAA+B;AAC/B,iBAA8B;AAWvB,MAAM,aAAa,CAAC,YAIrB;AACL,MAAI,QAAQ,SAAS,QAAW;AAC/B,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACpD;AAEA,MAAI,QAAQ,WAAW,QAAW;AACjC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACtD;AAEA,MAAI;AACJ,MAAI,QAAQ,SAAS,MAAM;AAC1B,WAAO;AAAA,EACR,WAAW,QAAQ,SAAS,OAAO;AAClC,WAAO;AAAA,EACR,WAAW,QAAQ,SAAS,MAAM;AACjC,WAAO,QAAQ;AAAA,EAChB;AAEA,MAAI;AACJ,MAAI,QAAQ,WAAW,MAAM;AAC5B,aAAS;AAAA,EACV,WAAW,QAAQ,WAAW,OAAO;AACpC,aAAS;AAAA,EACV,WAAW,QAAQ,WAAW,MAAM;AACnC,aAAS,QAAQ;AAAA,EAClB;AAEA,MAAI,YAAY;AAChB,MAAI,MAAM,QAAQ,QAAQ,IAAI,GAAG;AAChC,gBAAY,QAAQ,KAClB,IAAI,CAAC,OAAO;AACZ,iBAAO,kBAAG,IAAI,mBAAM,IAAI,GAAG,OAAQ;AAAA,IACpC,CAAC,EACA,KAAK,GAAG;AAAA,EACX,OAAO;AACN,oBAAY,kBAAG,QAAQ,MAAM,mBAAM,IAChC,QAAQ,KAAK,OACZ,QAAQ;AAAA,EACb;AAEA,SAAO;AAAA,IACN,YACG,yBAAS,QAAQ,SAAS,kBAAkB;AAAA,MAC9C,KAAK;AAAA,MACL,IAAI,QAAQ;AAAA,MACZ,OAAO;AAAA,IACR,CAAC;AAAA,IAED,cACG,yBAAS,QAAQ,SAAS,kBAAkB;AAAA,MAC9C,KAAK;AAAA,MACL,IAAI,QAAQ;AAAA,MACZ,WAAW;AAAA,IACZ,CAAC;AAAA,IACD,cACG,yBAAS,QAAQ,SAAS,kBAAkB;AAAA,MAC9C,KAAK;AAAA,MACL,IAAI,QAAQ;AAAA,MACZ,OAAO;AAAA,MACP,WAAW;AAAA,IACZ,CAAC;AAAA,IACD,cACG,yBAAS,QAAQ,SAAS,kBAAkB;AAAA,MAC9C,KAAK;AAAA,MACL,IAAI,QAAQ;AAAA,MACZ,OAAO;AAAA,IACR,CAAC;AAAA,EACF,EAAE,OAAO,OAAO;AACjB;AAGO,MAAM,wBAAoB,qBAAO,eAAe,EAAE,SAAS;AAC3D,MAAM,oBAAgB,qBAAO,WAAW,EAAE,SAAS;AAEnD,MAAM,UAAU,CAAC,iBAA8B,0CAA+B,YAAY;","names":[]}
package/neon/rls.d.cts ADDED
@@ -0,0 +1,20 @@
1
+ import { type AnyPgColumn, type PgPolicyToOption } from "../pg-core/index.cjs";
2
+ import { PgRole } from "../pg-core/roles.cjs";
3
+ import { type SQL } from "../sql/sql.cjs";
4
+ /**
5
+ * Generates a set of PostgreSQL row-level security (RLS) policies for CRUD operations based on the provided options.
6
+ *
7
+ * @param options - An object containing the policy configuration.
8
+ * @param options.role - The PostgreSQL role(s) to apply the policy to. Can be a single `PgRole` instance or an array of `PgRole` instances or role names.
9
+ * @param options.read - The SQL expression or boolean value that defines the read policy. Set to `true` to allow all reads, `false` to deny all reads, or provide a custom SQL expression. Set to `null` to prevent the policy from being generated.
10
+ * @param options.modify - The SQL expression or boolean value that defines the modify (insert, update, delete) policies. Set to `true` to allow all modifications, `false` to deny all modifications, or provide a custom SQL expression. Set to `null` to prevent policies from being generated.
11
+ * @returns An array of PostgreSQL policy definitions, one for each CRUD operation.
12
+ */
13
+ export declare const crudPolicy: (options: {
14
+ role: PgPolicyToOption;
15
+ read: SQL | boolean | null;
16
+ modify: SQL | boolean | null;
17
+ }) => (import("../pg-core/index.ts").PgPolicy | undefined)[];
18
+ export declare const authenticatedRole: PgRole;
19
+ export declare const anonymousRole: PgRole;
20
+ export declare const authUid: (userIdColumn: AnyPgColumn) => SQL<unknown>;
package/neon/rls.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { type AnyPgColumn, type PgPolicyToOption } from "../pg-core/index.js";
2
+ import { PgRole } from "../pg-core/roles.js";
3
+ import { type SQL } from "../sql/sql.js";
4
+ /**
5
+ * Generates a set of PostgreSQL row-level security (RLS) policies for CRUD operations based on the provided options.
6
+ *
7
+ * @param options - An object containing the policy configuration.
8
+ * @param options.role - The PostgreSQL role(s) to apply the policy to. Can be a single `PgRole` instance or an array of `PgRole` instances or role names.
9
+ * @param options.read - The SQL expression or boolean value that defines the read policy. Set to `true` to allow all reads, `false` to deny all reads, or provide a custom SQL expression. Set to `null` to prevent the policy from being generated.
10
+ * @param options.modify - The SQL expression or boolean value that defines the modify (insert, update, delete) policies. Set to `true` to allow all modifications, `false` to deny all modifications, or provide a custom SQL expression. Set to `null` to prevent policies from being generated.
11
+ * @returns An array of PostgreSQL policy definitions, one for each CRUD operation.
12
+ */
13
+ export declare const crudPolicy: (options: {
14
+ role: PgPolicyToOption;
15
+ read: SQL | boolean | null;
16
+ modify: SQL | boolean | null;
17
+ }) => (import("../pg-core/index.js").PgPolicy | undefined)[];
18
+ export declare const authenticatedRole: PgRole;
19
+ export declare const anonymousRole: PgRole;
20
+ export declare const authUid: (userIdColumn: AnyPgColumn) => SQL<unknown>;
package/neon/rls.js ADDED
@@ -0,0 +1,69 @@
1
+ import { is } from "../entity.js";
2
+ import { pgPolicy } from "../pg-core/index.js";
3
+ import { PgRole, pgRole } from "../pg-core/roles.js";
4
+ import { sql } from "../sql/sql.js";
5
+ const crudPolicy = (options) => {
6
+ if (options.read === void 0) {
7
+ throw new Error("crudPolicy requires a read policy");
8
+ }
9
+ if (options.modify === void 0) {
10
+ throw new Error("crudPolicy requires a modify policy");
11
+ }
12
+ let read;
13
+ if (options.read === true) {
14
+ read = sql`true`;
15
+ } else if (options.read === false) {
16
+ read = sql`false`;
17
+ } else if (options.read !== null) {
18
+ read = options.read;
19
+ }
20
+ let modify;
21
+ if (options.modify === true) {
22
+ modify = sql`true`;
23
+ } else if (options.modify === false) {
24
+ modify = sql`false`;
25
+ } else if (options.modify !== null) {
26
+ modify = options.modify;
27
+ }
28
+ let rolesName = "";
29
+ if (Array.isArray(options.role)) {
30
+ rolesName = options.role.map((it) => {
31
+ return is(it, PgRole) ? it.name : it;
32
+ }).join("-");
33
+ } else {
34
+ rolesName = is(options.role, PgRole) ? options.role.name : options.role;
35
+ }
36
+ return [
37
+ read && pgPolicy(`crud-${rolesName}-policy-select`, {
38
+ for: "select",
39
+ to: options.role,
40
+ using: read
41
+ }),
42
+ modify && pgPolicy(`crud-${rolesName}-policy-insert`, {
43
+ for: "insert",
44
+ to: options.role,
45
+ withCheck: modify
46
+ }),
47
+ modify && pgPolicy(`crud-${rolesName}-policy-update`, {
48
+ for: "update",
49
+ to: options.role,
50
+ using: modify,
51
+ withCheck: modify
52
+ }),
53
+ modify && pgPolicy(`crud-${rolesName}-policy-delete`, {
54
+ for: "delete",
55
+ to: options.role,
56
+ using: modify
57
+ })
58
+ ].filter(Boolean);
59
+ };
60
+ const authenticatedRole = pgRole("authenticated").existing();
61
+ const anonymousRole = pgRole("anonymous").existing();
62
+ const authUid = (userIdColumn) => sql`(select auth.user_id() = ${userIdColumn})`;
63
+ export {
64
+ anonymousRole,
65
+ authUid,
66
+ authenticatedRole,
67
+ crudPolicy
68
+ };
69
+ //# sourceMappingURL=rls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/neon/rls.ts"],"sourcesContent":["import { is } from '~/entity.ts';\nimport { type AnyPgColumn, pgPolicy, type PgPolicyToOption } from '~/pg-core/index.ts';\nimport { PgRole, pgRole } from '~/pg-core/roles.ts';\nimport { type SQL, sql } from '~/sql/sql.ts';\n\n/**\n * Generates a set of PostgreSQL row-level security (RLS) policies for CRUD operations based on the provided options.\n *\n * @param options - An object containing the policy configuration.\n * @param options.role - The PostgreSQL role(s) to apply the policy to. Can be a single `PgRole` instance or an array of `PgRole` instances or role names.\n * @param options.read - The SQL expression or boolean value that defines the read policy. Set to `true` to allow all reads, `false` to deny all reads, or provide a custom SQL expression. Set to `null` to prevent the policy from being generated.\n * @param options.modify - The SQL expression or boolean value that defines the modify (insert, update, delete) policies. Set to `true` to allow all modifications, `false` to deny all modifications, or provide a custom SQL expression. Set to `null` to prevent policies from being generated.\n * @returns An array of PostgreSQL policy definitions, one for each CRUD operation.\n */\nexport const crudPolicy = (options: {\n\trole: PgPolicyToOption;\n\tread: SQL | boolean | null;\n\tmodify: SQL | boolean | null;\n}) => {\n\tif (options.read === undefined) {\n\t\tthrow new Error('crudPolicy requires a read policy');\n\t}\n\n\tif (options.modify === undefined) {\n\t\tthrow new Error('crudPolicy requires a modify policy');\n\t}\n\n\tlet read: SQL | undefined;\n\tif (options.read === true) {\n\t\tread = sql`true`;\n\t} else if (options.read === false) {\n\t\tread = sql`false`;\n\t} else if (options.read !== null) {\n\t\tread = options.read;\n\t}\n\n\tlet modify: SQL | undefined;\n\tif (options.modify === true) {\n\t\tmodify = sql`true`;\n\t} else if (options.modify === false) {\n\t\tmodify = sql`false`;\n\t} else if (options.modify !== null) {\n\t\tmodify = options.modify;\n\t}\n\n\tlet rolesName = '';\n\tif (Array.isArray(options.role)) {\n\t\trolesName = options.role\n\t\t\t.map((it) => {\n\t\t\t\treturn is(it, PgRole) ? it.name : (it as string);\n\t\t\t})\n\t\t\t.join('-');\n\t} else {\n\t\trolesName = is(options.role, PgRole)\n\t\t\t? options.role.name\n\t\t\t: (options.role as string);\n\t}\n\n\treturn [\n\t\tread\n\t\t&& pgPolicy(`crud-${rolesName}-policy-select`, {\n\t\t\tfor: 'select',\n\t\t\tto: options.role,\n\t\t\tusing: read,\n\t\t}),\n\n\t\tmodify\n\t\t&& pgPolicy(`crud-${rolesName}-policy-insert`, {\n\t\t\tfor: 'insert',\n\t\t\tto: options.role,\n\t\t\twithCheck: modify,\n\t\t}),\n\t\tmodify\n\t\t&& pgPolicy(`crud-${rolesName}-policy-update`, {\n\t\t\tfor: 'update',\n\t\t\tto: options.role,\n\t\t\tusing: modify,\n\t\t\twithCheck: modify,\n\t\t}),\n\t\tmodify\n\t\t&& pgPolicy(`crud-${rolesName}-policy-delete`, {\n\t\t\tfor: 'delete',\n\t\t\tto: options.role,\n\t\t\tusing: modify,\n\t\t}),\n\t].filter(Boolean);\n};\n\n// These are default roles that Neon will set up.\nexport const authenticatedRole = pgRole('authenticated').existing();\nexport const anonymousRole = pgRole('anonymous').existing();\n\nexport const authUid = (userIdColumn: AnyPgColumn) => sql`(select auth.user_id() = ${userIdColumn})`;\n"],"mappings":"AAAA,SAAS,UAAU;AACnB,SAA2B,gBAAuC;AAClE,SAAS,QAAQ,cAAc;AAC/B,SAAmB,WAAW;AAWvB,MAAM,aAAa,CAAC,YAIrB;AACL,MAAI,QAAQ,SAAS,QAAW;AAC/B,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACpD;AAEA,MAAI,QAAQ,WAAW,QAAW;AACjC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACtD;AAEA,MAAI;AACJ,MAAI,QAAQ,SAAS,MAAM;AAC1B,WAAO;AAAA,EACR,WAAW,QAAQ,SAAS,OAAO;AAClC,WAAO;AAAA,EACR,WAAW,QAAQ,SAAS,MAAM;AACjC,WAAO,QAAQ;AAAA,EAChB;AAEA,MAAI;AACJ,MAAI,QAAQ,WAAW,MAAM;AAC5B,aAAS;AAAA,EACV,WAAW,QAAQ,WAAW,OAAO;AACpC,aAAS;AAAA,EACV,WAAW,QAAQ,WAAW,MAAM;AACnC,aAAS,QAAQ;AAAA,EAClB;AAEA,MAAI,YAAY;AAChB,MAAI,MAAM,QAAQ,QAAQ,IAAI,GAAG;AAChC,gBAAY,QAAQ,KAClB,IAAI,CAAC,OAAO;AACZ,aAAO,GAAG,IAAI,MAAM,IAAI,GAAG,OAAQ;AAAA,IACpC,CAAC,EACA,KAAK,GAAG;AAAA,EACX,OAAO;AACN,gBAAY,GAAG,QAAQ,MAAM,MAAM,IAChC,QAAQ,KAAK,OACZ,QAAQ;AAAA,EACb;AAEA,SAAO;AAAA,IACN,QACG,SAAS,QAAQ,SAAS,kBAAkB;AAAA,MAC9C,KAAK;AAAA,MACL,IAAI,QAAQ;AAAA,MACZ,OAAO;AAAA,IACR,CAAC;AAAA,IAED,UACG,SAAS,QAAQ,SAAS,kBAAkB;AAAA,MAC9C,KAAK;AAAA,MACL,IAAI,QAAQ;AAAA,MACZ,WAAW;AAAA,IACZ,CAAC;AAAA,IACD,UACG,SAAS,QAAQ,SAAS,kBAAkB;AAAA,MAC9C,KAAK;AAAA,MACL,IAAI,QAAQ;AAAA,MACZ,OAAO;AAAA,MACP,WAAW;AAAA,IACZ,CAAC;AAAA,IACD,UACG,SAAS,QAAQ,SAAS,kBAAkB;AAAA,MAC9C,KAAK;AAAA,MACL,IAAI,QAAQ;AAAA,MACZ,OAAO;AAAA,IACR,CAAC;AAAA,EACF,EAAE,OAAO,OAAO;AACjB;AAGO,MAAM,oBAAoB,OAAO,eAAe,EAAE,SAAS;AAC3D,MAAM,gBAAgB,OAAO,WAAW,EAAE,SAAS;AAEnD,MAAM,UAAU,CAAC,iBAA8B,+BAA+B,YAAY;","names":[]}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "0.35.3",
3
+ "version": "0.36.0-19f042a",
4
4
  "description": "Drizzle ORM package for SQL databases",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "build": "scripts/build.ts",
7
+ "p": "prisma generate --schema src/prisma/schema.prisma",
8
+ "build": "pnpm p && scripts/build.ts",
8
9
  "b": "pnpm build",
9
10
  "test:types": "cd type-tests && tsc",
10
11
  "test": "vitest run",
@@ -45,7 +46,7 @@
45
46
  "peerDependencies": {
46
47
  "@aws-sdk/client-rds-data": ">=3",
47
48
  "@cloudflare/workers-types": ">=3",
48
- "@electric-sql/pglite": ">=0.1.1",
49
+ "@electric-sql/pglite": ">=0.2.0",
49
50
  "@libsql/client": ">=0.10.0",
50
51
  "@libsql/client-wasm": ">=0.10.0",
51
52
  "@neondatabase/serverless": ">=0.1",
@@ -130,6 +131,9 @@
130
131
  "@libsql/client": {
131
132
  "optional": true
132
133
  },
134
+ "@libsql/client-wasm": {
135
+ "optional": true
136
+ },
133
137
  "@opentelemetry/api": {
134
138
  "optional": true
135
139
  },
@@ -512,54 +516,6 @@
512
516
  "types": "./view-common.d.ts",
513
517
  "default": "./view-common.js"
514
518
  },
515
- "./bun-sqlite/driver": {
516
- "import": {
517
- "types": "./bun-sqlite/driver.d.ts",
518
- "default": "./bun-sqlite/driver.js"
519
- },
520
- "require": {
521
- "types": "./bun-sqlite/driver.d.cts",
522
- "default": "./bun-sqlite/driver.cjs"
523
- },
524
- "types": "./bun-sqlite/driver.d.ts",
525
- "default": "./bun-sqlite/driver.js"
526
- },
527
- "./bun-sqlite": {
528
- "import": {
529
- "types": "./bun-sqlite/index.d.ts",
530
- "default": "./bun-sqlite/index.js"
531
- },
532
- "require": {
533
- "types": "./bun-sqlite/index.d.cts",
534
- "default": "./bun-sqlite/index.cjs"
535
- },
536
- "types": "./bun-sqlite/index.d.ts",
537
- "default": "./bun-sqlite/index.js"
538
- },
539
- "./bun-sqlite/migrator": {
540
- "import": {
541
- "types": "./bun-sqlite/migrator.d.ts",
542
- "default": "./bun-sqlite/migrator.js"
543
- },
544
- "require": {
545
- "types": "./bun-sqlite/migrator.d.cts",
546
- "default": "./bun-sqlite/migrator.cjs"
547
- },
548
- "types": "./bun-sqlite/migrator.d.ts",
549
- "default": "./bun-sqlite/migrator.js"
550
- },
551
- "./bun-sqlite/session": {
552
- "import": {
553
- "types": "./bun-sqlite/session.d.ts",
554
- "default": "./bun-sqlite/session.js"
555
- },
556
- "require": {
557
- "types": "./bun-sqlite/session.d.cts",
558
- "default": "./bun-sqlite/session.cjs"
559
- },
560
- "types": "./bun-sqlite/session.d.ts",
561
- "default": "./bun-sqlite/session.js"
562
- },
563
519
  "./better-sqlite3/driver": {
564
520
  "import": {
565
521
  "types": "./better-sqlite3/driver.d.ts",
@@ -608,6 +564,54 @@
608
564
  "types": "./better-sqlite3/session.d.ts",
609
565
  "default": "./better-sqlite3/session.js"
610
566
  },
567
+ "./bun-sqlite/driver": {
568
+ "import": {
569
+ "types": "./bun-sqlite/driver.d.ts",
570
+ "default": "./bun-sqlite/driver.js"
571
+ },
572
+ "require": {
573
+ "types": "./bun-sqlite/driver.d.cts",
574
+ "default": "./bun-sqlite/driver.cjs"
575
+ },
576
+ "types": "./bun-sqlite/driver.d.ts",
577
+ "default": "./bun-sqlite/driver.js"
578
+ },
579
+ "./bun-sqlite": {
580
+ "import": {
581
+ "types": "./bun-sqlite/index.d.ts",
582
+ "default": "./bun-sqlite/index.js"
583
+ },
584
+ "require": {
585
+ "types": "./bun-sqlite/index.d.cts",
586
+ "default": "./bun-sqlite/index.cjs"
587
+ },
588
+ "types": "./bun-sqlite/index.d.ts",
589
+ "default": "./bun-sqlite/index.js"
590
+ },
591
+ "./bun-sqlite/migrator": {
592
+ "import": {
593
+ "types": "./bun-sqlite/migrator.d.ts",
594
+ "default": "./bun-sqlite/migrator.js"
595
+ },
596
+ "require": {
597
+ "types": "./bun-sqlite/migrator.d.cts",
598
+ "default": "./bun-sqlite/migrator.cjs"
599
+ },
600
+ "types": "./bun-sqlite/migrator.d.ts",
601
+ "default": "./bun-sqlite/migrator.js"
602
+ },
603
+ "./bun-sqlite/session": {
604
+ "import": {
605
+ "types": "./bun-sqlite/session.d.ts",
606
+ "default": "./bun-sqlite/session.js"
607
+ },
608
+ "require": {
609
+ "types": "./bun-sqlite/session.d.cts",
610
+ "default": "./bun-sqlite/session.cjs"
611
+ },
612
+ "types": "./bun-sqlite/session.d.ts",
613
+ "default": "./bun-sqlite/session.js"
614
+ },
611
615
  "./d1/driver": {
612
616
  "import": {
613
617
  "types": "./d1/driver.d.ts",
@@ -1112,6 +1116,30 @@
1112
1116
  "types": "./mysql2/session.d.ts",
1113
1117
  "default": "./mysql2/session.js"
1114
1118
  },
1119
+ "./neon": {
1120
+ "import": {
1121
+ "types": "./neon/index.d.ts",
1122
+ "default": "./neon/index.js"
1123
+ },
1124
+ "require": {
1125
+ "types": "./neon/index.d.cts",
1126
+ "default": "./neon/index.cjs"
1127
+ },
1128
+ "types": "./neon/index.d.ts",
1129
+ "default": "./neon/index.js"
1130
+ },
1131
+ "./neon/rls": {
1132
+ "import": {
1133
+ "types": "./neon/rls.d.ts",
1134
+ "default": "./neon/rls.js"
1135
+ },
1136
+ "require": {
1137
+ "types": "./neon/rls.d.cts",
1138
+ "default": "./neon/rls.cjs"
1139
+ },
1140
+ "types": "./neon/rls.d.ts",
1141
+ "default": "./neon/rls.js"
1142
+ },
1115
1143
  "./neon-http/driver": {
1116
1144
  "import": {
1117
1145
  "types": "./neon-http/driver.d.ts",
@@ -1400,6 +1428,18 @@
1400
1428
  "types": "./pg-core/indexes.d.ts",
1401
1429
  "default": "./pg-core/indexes.js"
1402
1430
  },
1431
+ "./pg-core/policies": {
1432
+ "import": {
1433
+ "types": "./pg-core/policies.d.ts",
1434
+ "default": "./pg-core/policies.js"
1435
+ },
1436
+ "require": {
1437
+ "types": "./pg-core/policies.d.cts",
1438
+ "default": "./pg-core/policies.cjs"
1439
+ },
1440
+ "types": "./pg-core/policies.d.ts",
1441
+ "default": "./pg-core/policies.js"
1442
+ },
1403
1443
  "./pg-core/primary-keys": {
1404
1444
  "import": {
1405
1445
  "types": "./pg-core/primary-keys.d.ts",
@@ -1412,6 +1452,18 @@
1412
1452
  "types": "./pg-core/primary-keys.d.ts",
1413
1453
  "default": "./pg-core/primary-keys.js"
1414
1454
  },
1455
+ "./pg-core/roles": {
1456
+ "import": {
1457
+ "types": "./pg-core/roles.d.ts",
1458
+ "default": "./pg-core/roles.js"
1459
+ },
1460
+ "require": {
1461
+ "types": "./pg-core/roles.d.cts",
1462
+ "default": "./pg-core/roles.cjs"
1463
+ },
1464
+ "types": "./pg-core/roles.d.ts",
1465
+ "default": "./pg-core/roles.js"
1466
+ },
1415
1467
  "./pg-core/schema": {
1416
1468
  "import": {
1417
1469
  "types": "./pg-core/schema.d.ts",
@@ -2072,6 +2124,30 @@
2072
2124
  "types": "./sqlite-proxy/session.d.ts",
2073
2125
  "default": "./sqlite-proxy/session.js"
2074
2126
  },
2127
+ "./supabase": {
2128
+ "import": {
2129
+ "types": "./supabase/index.d.ts",
2130
+ "default": "./supabase/index.js"
2131
+ },
2132
+ "require": {
2133
+ "types": "./supabase/index.d.cts",
2134
+ "default": "./supabase/index.cjs"
2135
+ },
2136
+ "types": "./supabase/index.d.ts",
2137
+ "default": "./supabase/index.js"
2138
+ },
2139
+ "./supabase/rls": {
2140
+ "import": {
2141
+ "types": "./supabase/rls.d.ts",
2142
+ "default": "./supabase/rls.js"
2143
+ },
2144
+ "require": {
2145
+ "types": "./supabase/rls.d.cts",
2146
+ "default": "./supabase/rls.cjs"
2147
+ },
2148
+ "types": "./supabase/rls.d.ts",
2149
+ "default": "./supabase/rls.js"
2150
+ },
2075
2151
  "./tidb-serverless/driver": {
2076
2152
  "import": {
2077
2153
  "types": "./tidb-serverless/driver.d.ts",
package/pg-core/index.cjs CHANGED
@@ -22,8 +22,10 @@ __reExport(pg_core_exports, require("./db.cjs"), module.exports);
22
22
  __reExport(pg_core_exports, require("./dialect.cjs"), module.exports);
23
23
  __reExport(pg_core_exports, require("./foreign-keys.cjs"), module.exports);
24
24
  __reExport(pg_core_exports, require("./indexes.cjs"), module.exports);
25
+ __reExport(pg_core_exports, require("./policies.cjs"), module.exports);
25
26
  __reExport(pg_core_exports, require("./primary-keys.cjs"), module.exports);
26
27
  __reExport(pg_core_exports, require("./query-builders/index.cjs"), module.exports);
28
+ __reExport(pg_core_exports, require("./roles.cjs"), module.exports);
27
29
  __reExport(pg_core_exports, require("./schema.cjs"), module.exports);
28
30
  __reExport(pg_core_exports, require("./sequence.cjs"), module.exports);
29
31
  __reExport(pg_core_exports, require("./session.cjs"), module.exports);
@@ -43,8 +45,10 @@ __reExport(pg_core_exports, require("./view.cjs"), module.exports);
43
45
  ...require("./dialect.cjs"),
44
46
  ...require("./foreign-keys.cjs"),
45
47
  ...require("./indexes.cjs"),
48
+ ...require("./policies.cjs"),
46
49
  ...require("./primary-keys.cjs"),
47
50
  ...require("./query-builders/index.cjs"),
51
+ ...require("./roles.cjs"),
48
52
  ...require("./schema.cjs"),
49
53
  ...require("./sequence.cjs"),
50
54
  ...require("./session.cjs"),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/pg-core/index.ts"],"sourcesContent":["export * from './alias.ts';\nexport * from './checks.ts';\nexport * from './columns/index.ts';\nexport * from './db.ts';\nexport * from './dialect.ts';\nexport * from './foreign-keys.ts';\nexport * from './indexes.ts';\nexport * from './primary-keys.ts';\nexport * from './query-builders/index.ts';\nexport * from './schema.ts';\nexport * from './sequence.ts';\nexport * from './session.ts';\nexport * from './subquery.ts';\nexport * from './table.ts';\nexport * from './unique-constraint.ts';\nexport * from './utils.ts';\nexport * from './utils/index.ts';\nexport * from './view-common.ts';\nexport * from './view.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,4BAAc,uBAAd;AACA,4BAAc,wBADd;AAEA,4BAAc,+BAFd;AAGA,4BAAc,oBAHd;AAIA,4BAAc,yBAJd;AAKA,4BAAc,8BALd;AAMA,4BAAc,yBANd;AAOA,4BAAc,8BAPd;AAQA,4BAAc,sCARd;AASA,4BAAc,wBATd;AAUA,4BAAc,0BAVd;AAWA,4BAAc,yBAXd;AAYA,4BAAc,0BAZd;AAaA,4BAAc,uBAbd;AAcA,4BAAc,mCAdd;AAeA,4BAAc,uBAfd;AAgBA,4BAAc,6BAhBd;AAiBA,4BAAc,6BAjBd;AAkBA,4BAAc,sBAlBd;","names":[]}
1
+ {"version":3,"sources":["../../src/pg-core/index.ts"],"sourcesContent":["export * from './alias.ts';\nexport * from './checks.ts';\nexport * from './columns/index.ts';\nexport * from './db.ts';\nexport * from './dialect.ts';\nexport * from './foreign-keys.ts';\nexport * from './indexes.ts';\nexport * from './policies.ts';\nexport * from './primary-keys.ts';\nexport * from './query-builders/index.ts';\nexport * from './roles.ts';\nexport * from './schema.ts';\nexport * from './sequence.ts';\nexport * from './session.ts';\nexport * from './subquery.ts';\nexport * from './table.ts';\nexport * from './unique-constraint.ts';\nexport * from './utils.ts';\nexport * from './utils/index.ts';\nexport * from './view-common.ts';\nexport * from './view.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,4BAAc,uBAAd;AACA,4BAAc,wBADd;AAEA,4BAAc,+BAFd;AAGA,4BAAc,oBAHd;AAIA,4BAAc,yBAJd;AAKA,4BAAc,8BALd;AAMA,4BAAc,yBANd;AAOA,4BAAc,0BAPd;AAQA,4BAAc,8BARd;AASA,4BAAc,sCATd;AAUA,4BAAc,uBAVd;AAWA,4BAAc,wBAXd;AAYA,4BAAc,0BAZd;AAaA,4BAAc,yBAbd;AAcA,4BAAc,0BAdd;AAeA,4BAAc,uBAfd;AAgBA,4BAAc,mCAhBd;AAiBA,4BAAc,uBAjBd;AAkBA,4BAAc,6BAlBd;AAmBA,4BAAc,6BAnBd;AAoBA,4BAAc,sBApBd;","names":[]}
@@ -5,8 +5,10 @@ export * from "./db.cjs";
5
5
  export * from "./dialect.cjs";
6
6
  export * from "./foreign-keys.cjs";
7
7
  export * from "./indexes.cjs";
8
+ export * from "./policies.cjs";
8
9
  export * from "./primary-keys.cjs";
9
10
  export * from "./query-builders/index.cjs";
11
+ export * from "./roles.cjs";
10
12
  export * from "./schema.cjs";
11
13
  export * from "./sequence.cjs";
12
14
  export * from "./session.cjs";
@@ -5,8 +5,10 @@ export * from "./db.js";
5
5
  export * from "./dialect.js";
6
6
  export * from "./foreign-keys.js";
7
7
  export * from "./indexes.js";
8
+ export * from "./policies.js";
8
9
  export * from "./primary-keys.js";
9
10
  export * from "./query-builders/index.js";
11
+ export * from "./roles.js";
10
12
  export * from "./schema.js";
11
13
  export * from "./sequence.js";
12
14
  export * from "./session.js";
package/pg-core/index.js CHANGED
@@ -5,8 +5,10 @@ export * from "./db.js";
5
5
  export * from "./dialect.js";
6
6
  export * from "./foreign-keys.js";
7
7
  export * from "./indexes.js";
8
+ export * from "./policies.js";
8
9
  export * from "./primary-keys.js";
9
10
  export * from "./query-builders/index.js";
11
+ export * from "./roles.js";
10
12
  export * from "./schema.js";
11
13
  export * from "./sequence.js";
12
14
  export * from "./session.js";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/pg-core/index.ts"],"sourcesContent":["export * from './alias.ts';\nexport * from './checks.ts';\nexport * from './columns/index.ts';\nexport * from './db.ts';\nexport * from './dialect.ts';\nexport * from './foreign-keys.ts';\nexport * from './indexes.ts';\nexport * from './primary-keys.ts';\nexport * from './query-builders/index.ts';\nexport * from './schema.ts';\nexport * from './sequence.ts';\nexport * from './session.ts';\nexport * from './subquery.ts';\nexport * from './table.ts';\nexport * from './unique-constraint.ts';\nexport * from './utils.ts';\nexport * from './utils/index.ts';\nexport * from './view-common.ts';\nexport * from './view.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../src/pg-core/index.ts"],"sourcesContent":["export * from './alias.ts';\nexport * from './checks.ts';\nexport * from './columns/index.ts';\nexport * from './db.ts';\nexport * from './dialect.ts';\nexport * from './foreign-keys.ts';\nexport * from './indexes.ts';\nexport * from './policies.ts';\nexport * from './primary-keys.ts';\nexport * from './query-builders/index.ts';\nexport * from './roles.ts';\nexport * from './schema.ts';\nexport * from './sequence.ts';\nexport * from './session.ts';\nexport * from './subquery.ts';\nexport * from './table.ts';\nexport * from './unique-constraint.ts';\nexport * from './utils.ts';\nexport * from './utils/index.ts';\nexport * from './view-common.ts';\nexport * from './view.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var policies_exports = {};
20
+ __export(policies_exports, {
21
+ PgPolicy: () => PgPolicy,
22
+ pgPolicy: () => pgPolicy
23
+ });
24
+ module.exports = __toCommonJS(policies_exports);
25
+ var import_entity = require("../entity.cjs");
26
+ class PgPolicy {
27
+ constructor(name, config) {
28
+ this.name = name;
29
+ if (config) {
30
+ this.as = config.as;
31
+ this.for = config.for;
32
+ this.to = config.to;
33
+ this.using = config.using;
34
+ this.withCheck = config.withCheck;
35
+ }
36
+ }
37
+ static [import_entity.entityKind] = "PgPolicy";
38
+ as;
39
+ for;
40
+ to;
41
+ using;
42
+ withCheck;
43
+ /** @internal */
44
+ _linkedTable;
45
+ link(table) {
46
+ this._linkedTable = table;
47
+ return this;
48
+ }
49
+ }
50
+ function pgPolicy(name, config) {
51
+ return new PgPolicy(name, config);
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ PgPolicy,
56
+ pgPolicy
57
+ });
58
+ //# sourceMappingURL=policies.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/pg-core/policies.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { SQL } from '~/sql/sql.ts';\nimport type { PgRole } from './roles.ts';\nimport type { PgTable } from './table.ts';\n\nexport type PgPolicyToOption =\n\t| 'public'\n\t| 'current_role'\n\t| 'current_user'\n\t| 'session_user'\n\t| (string & {})\n\t| PgPolicyToOption[]\n\t| PgRole;\n\nexport interface PgPolicyConfig {\n\tas?: 'permissive' | 'restrictive';\n\tfor?: 'all' | 'select' | 'insert' | 'update' | 'delete';\n\tto?: PgPolicyToOption;\n\tusing?: SQL;\n\twithCheck?: SQL;\n}\n\nexport class PgPolicy implements PgPolicyConfig {\n\tstatic readonly [entityKind]: string = 'PgPolicy';\n\n\treadonly as: PgPolicyConfig['as'];\n\treadonly for: PgPolicyConfig['for'];\n\treadonly to: PgPolicyConfig['to'];\n\treadonly using: PgPolicyConfig['using'];\n\treadonly withCheck: PgPolicyConfig['withCheck'];\n\n\t/** @internal */\n\t_linkedTable?: PgTable;\n\n\tconstructor(\n\t\treadonly name: string,\n\t\tconfig?: PgPolicyConfig,\n\t) {\n\t\tif (config) {\n\t\t\tthis.as = config.as;\n\t\t\tthis.for = config.for;\n\t\t\tthis.to = config.to;\n\t\t\tthis.using = config.using;\n\t\t\tthis.withCheck = config.withCheck;\n\t\t}\n\t}\n\n\tlink(table: PgTable): this {\n\t\tthis._linkedTable = table;\n\t\treturn this;\n\t}\n}\n\nexport function pgPolicy(name: string, config?: PgPolicyConfig) {\n\treturn new PgPolicy(name, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAsBpB,MAAM,SAAmC;AAAA,EAY/C,YACU,MACT,QACC;AAFQ;AAGT,QAAI,QAAQ;AACX,WAAK,KAAK,OAAO;AACjB,WAAK,MAAM,OAAO;AAClB,WAAK,KAAK,OAAO;AACjB,WAAK,QAAQ,OAAO;AACpB,WAAK,YAAY,OAAO;AAAA,IACzB;AAAA,EACD;AAAA,EAtBA,QAAiB,wBAAU,IAAY;AAAA,EAE9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAGT;AAAA,EAeA,KAAK,OAAsB;AAC1B,SAAK,eAAe;AACpB,WAAO;AAAA,EACR;AACD;AAEO,SAAS,SAAS,MAAc,QAAyB;AAC/D,SAAO,IAAI,SAAS,MAAM,MAAM;AACjC;","names":[]}
@@ -0,0 +1,24 @@
1
+ import { entityKind } from "../entity.cjs";
2
+ import type { SQL } from "../sql/sql.cjs";
3
+ import type { PgRole } from "./roles.cjs";
4
+ import type { PgTable } from "./table.cjs";
5
+ export type PgPolicyToOption = 'public' | 'current_role' | 'current_user' | 'session_user' | (string & {}) | PgPolicyToOption[] | PgRole;
6
+ export interface PgPolicyConfig {
7
+ as?: 'permissive' | 'restrictive';
8
+ for?: 'all' | 'select' | 'insert' | 'update' | 'delete';
9
+ to?: PgPolicyToOption;
10
+ using?: SQL;
11
+ withCheck?: SQL;
12
+ }
13
+ export declare class PgPolicy implements PgPolicyConfig {
14
+ readonly name: string;
15
+ static readonly [entityKind]: string;
16
+ readonly as: PgPolicyConfig['as'];
17
+ readonly for: PgPolicyConfig['for'];
18
+ readonly to: PgPolicyConfig['to'];
19
+ readonly using: PgPolicyConfig['using'];
20
+ readonly withCheck: PgPolicyConfig['withCheck'];
21
+ constructor(name: string, config?: PgPolicyConfig);
22
+ link(table: PgTable): this;
23
+ }
24
+ export declare function pgPolicy(name: string, config?: PgPolicyConfig): PgPolicy;