@wrelik/db 0.1.0 → 0.1.3

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.
@@ -0,0 +1,23 @@
1
+
2
+ > @wrelik/db@0.1.3 build /home/runner/work/wrelik-kit/wrelik-kit/packages/db
3
+ > tsup src/index.ts src/unsupported.ts --format cjs,esm --dts --clean
4
+
5
+ CLI Building entry: src/index.ts, src/unsupported.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Target: es2022
9
+ CLI Cleaning output folder
10
+ CJS Build start
11
+ ESM Build start
12
+ ESM dist/index.mjs 958.00 B
13
+ ESM dist/unsupported.mjs 402.00 B
14
+ ESM ⚡️ Build success in 58ms
15
+ CJS dist/index.js 2.08 KB
16
+ CJS dist/unsupported.js 1.28 KB
17
+ CJS ⚡️ Build success in 60ms
18
+ DTS Build start
19
+ DTS ⚡️ Build success in 3421ms
20
+ DTS dist/index.d.ts 483.00 B
21
+ DTS dist/unsupported.d.ts 74.00 B
22
+ DTS dist/index.d.mts 483.00 B
23
+ DTS dist/unsupported.d.mts 74.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @wrelik/db
2
2
 
3
+ ## 0.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [2b9cbf7]
8
+ - @wrelik/errors@0.2.1
9
+
10
+ ## 0.1.2
11
+
12
+ ### Patch Changes
13
+
14
+ - a38ebcb: Add React Native / Expo support and enforce server-only boundaries.
15
+ - Updated dependencies [a38ebcb]
16
+ - @wrelik/errors@0.2.0
17
+
18
+ ## 0.1.1
19
+
20
+ ### Patch Changes
21
+
22
+ - Update publishConfig to access:public for all packages.
23
+ - Updated dependencies
24
+ - @wrelik/errors@0.1.1
25
+
3
26
  ## 0.1.0
4
27
 
5
28
  ### Minor Changes
@@ -0,0 +1,7 @@
1
+ type AccessChecker = (userId: string, tenantId: string) => Promise<boolean>;
2
+ declare function setTenantAccessChecker(checker: AccessChecker): void;
3
+ declare function assertTenantAccess(userId: string, tenantId: string): Promise<void>;
4
+ declare function withTenant<T>(tenantId: string, fn: (tenantId: string) => Promise<T>): Promise<T>;
5
+ declare function getPrismaSingleton<T>(factory: () => T): T;
6
+
7
+ export { assertTenantAccess, getPrismaSingleton, setTenantAccessChecker, withTenant };
@@ -0,0 +1,7 @@
1
+ type AccessChecker = (userId: string, tenantId: string) => Promise<boolean>;
2
+ declare function setTenantAccessChecker(checker: AccessChecker): void;
3
+ declare function assertTenantAccess(userId: string, tenantId: string): Promise<void>;
4
+ declare function withTenant<T>(tenantId: string, fn: (tenantId: string) => Promise<T>): Promise<T>;
5
+ declare function getPrismaSingleton<T>(factory: () => T): T;
6
+
7
+ export { assertTenantAccess, getPrismaSingleton, setTenantAccessChecker, withTenant };
package/dist/index.js ADDED
@@ -0,0 +1,63 @@
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
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ assertTenantAccess: () => assertTenantAccess,
24
+ getPrismaSingleton: () => getPrismaSingleton,
25
+ setTenantAccessChecker: () => setTenantAccessChecker,
26
+ withTenant: () => withTenant
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var import_errors = require("@wrelik/errors");
30
+ var accessChecker = async () => false;
31
+ function setTenantAccessChecker(checker) {
32
+ accessChecker = checker;
33
+ }
34
+ async function assertTenantAccess(userId, tenantId) {
35
+ if (!userId || !tenantId) {
36
+ throw new import_errors.TenantRequiredError();
37
+ }
38
+ const allowed = await accessChecker(userId, tenantId);
39
+ if (!allowed) {
40
+ throw new import_errors.PermissionDeniedError(`User ${userId} does not have access to tenant ${tenantId}`);
41
+ }
42
+ }
43
+ function withTenant(tenantId, fn) {
44
+ if (!tenantId) {
45
+ throw new import_errors.TenantRequiredError();
46
+ }
47
+ return fn(tenantId);
48
+ }
49
+ function getPrismaSingleton(factory) {
50
+ const globalForPrisma = global;
51
+ const prisma = globalForPrisma.prisma || factory();
52
+ if (process.env.NODE_ENV !== "production") {
53
+ globalForPrisma.prisma = prisma;
54
+ }
55
+ return prisma;
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ assertTenantAccess,
60
+ getPrismaSingleton,
61
+ setTenantAccessChecker,
62
+ withTenant
63
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,35 @@
1
+ // src/index.ts
2
+ import { PermissionDeniedError, TenantRequiredError } from "@wrelik/errors";
3
+ var accessChecker = async () => false;
4
+ function setTenantAccessChecker(checker) {
5
+ accessChecker = checker;
6
+ }
7
+ async function assertTenantAccess(userId, tenantId) {
8
+ if (!userId || !tenantId) {
9
+ throw new TenantRequiredError();
10
+ }
11
+ const allowed = await accessChecker(userId, tenantId);
12
+ if (!allowed) {
13
+ throw new PermissionDeniedError(`User ${userId} does not have access to tenant ${tenantId}`);
14
+ }
15
+ }
16
+ function withTenant(tenantId, fn) {
17
+ if (!tenantId) {
18
+ throw new TenantRequiredError();
19
+ }
20
+ return fn(tenantId);
21
+ }
22
+ function getPrismaSingleton(factory) {
23
+ const globalForPrisma = global;
24
+ const prisma = globalForPrisma.prisma || factory();
25
+ if (process.env.NODE_ENV !== "production") {
26
+ globalForPrisma.prisma = prisma;
27
+ }
28
+ return prisma;
29
+ }
30
+ export {
31
+ assertTenantAccess,
32
+ getPrismaSingleton,
33
+ setTenantAccessChecker,
34
+ withTenant
35
+ };
@@ -0,0 +1,3 @@
1
+ declare function unsupported(): void;
2
+
3
+ export { unsupported as default };
@@ -0,0 +1,3 @@
1
+ declare function unsupported(): void;
2
+
3
+ export { unsupported as default };
@@ -0,0 +1,33 @@
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
+
20
+ // src/unsupported.ts
21
+ var unsupported_exports = {};
22
+ __export(unsupported_exports, {
23
+ default: () => unsupported
24
+ });
25
+ module.exports = __toCommonJS(unsupported_exports);
26
+ function unsupported() {
27
+ throw new Error(
28
+ "This package is server-only and cannot be used in client/mobile environments. Access this functionality via a backend API instead."
29
+ );
30
+ }
31
+ throw new Error(
32
+ "This package is server-only and cannot be used in client/mobile environments. Access this functionality via a backend API instead."
33
+ );
@@ -0,0 +1,12 @@
1
+ // src/unsupported.ts
2
+ function unsupported() {
3
+ throw new Error(
4
+ "This package is server-only and cannot be used in client/mobile environments. Access this functionality via a backend API instead."
5
+ );
6
+ }
7
+ throw new Error(
8
+ "This package is server-only and cannot be used in client/mobile environments. Access this functionality via a backend API instead."
9
+ );
10
+ export {
11
+ unsupported as default
12
+ };
package/package.json CHANGED
@@ -1,20 +1,29 @@
1
1
  {
2
2
  "name": "@wrelik/db",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/lwhite702/wrelik-kit.git",
10
+ "directory": "packages/db"
11
+ },
4
12
  "main": "./dist/index.js",
5
13
  "types": "./dist/index.d.ts",
14
+ "react-native": "./dist/unsupported.js",
6
15
  "dependencies": {
7
- "@wrelik/errors": "0.1.0"
16
+ "@wrelik/errors": "0.2.1"
8
17
  },
9
18
  "devDependencies": {
10
19
  "@types/node": "^25.2.0",
11
20
  "tsup": "^8.0.1",
12
21
  "vitest": "^1.2.2",
13
- "@wrelik/eslint-config": "0.1.0",
14
- "@wrelik/tsconfig": "0.1.0"
22
+ "@wrelik/eslint-config": "0.1.1",
23
+ "@wrelik/tsconfig": "0.1.1"
15
24
  },
16
25
  "scripts": {
17
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
26
+ "build": "tsup src/index.ts src/unsupported.ts --format cjs,esm --dts --clean",
18
27
  "lint": "eslint src/",
19
28
  "test": "vitest run --passWithNoTests"
20
29
  }
@@ -0,0 +1,14 @@
1
+ export default function unsupported() {
2
+ throw new Error(
3
+ 'This package is server-only and cannot be used in client/mobile environments. ' +
4
+ 'Access this functionality via a backend API instead.',
5
+ );
6
+ }
7
+
8
+ // Using a Proxy to trap named imports if possible, or just the top level throw is usually enough for side-effect imports.
9
+ // But for named imports, we might need to export them?
10
+ // Since we can't mock all exports, the top level throw is best.
11
+ throw new Error(
12
+ 'This package is server-only and cannot be used in client/mobile environments. ' +
13
+ 'Access this functionality via a backend API instead.',
14
+ );
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "extends": "@wrelik/tsconfig/node.json",
3
3
  "compilerOptions": {
4
- "outDir": "dist"
4
+ "outDir": "dist", "skipLibCheck": true
5
5
  },
6
6
  "include": ["src"]
7
7
  }