@wrelik/db 0.1.0 → 0.1.2
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/.turbo/turbo-build.log +23 -0
- package/CHANGELOG.md +16 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +63 -0
- package/dist/index.mjs +35 -0
- package/dist/unsupported.d.mts +3 -0
- package/dist/unsupported.d.ts +3 -0
- package/dist/unsupported.js +33 -0
- package/dist/unsupported.mjs +12 -0
- package/package.json +14 -5
- package/src/unsupported.ts +14 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
> @wrelik/db@0.1.2 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
|
+
[34mCLI[39m Building entry: src/index.ts, src/unsupported.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.5.1
|
|
8
|
+
[34mCLI[39m Target: es2022
|
|
9
|
+
[34mCLI[39m Cleaning output folder
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[34mESM[39m Build start
|
|
12
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m958.00 B[39m
|
|
13
|
+
[32mESM[39m [1mdist/unsupported.mjs [22m[32m402.00 B[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 83ms
|
|
15
|
+
[32mCJS[39m [1mdist/index.js [22m[32m2.08 KB[39m
|
|
16
|
+
[32mCJS[39m [1mdist/unsupported.js [22m[32m1.28 KB[39m
|
|
17
|
+
[32mCJS[39m ⚡️ Build success in 85ms
|
|
18
|
+
[34mDTS[39m Build start
|
|
19
|
+
[32mDTS[39m ⚡️ Build success in 3142ms
|
|
20
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m483.00 B[39m
|
|
21
|
+
[32mDTS[39m [1mdist/unsupported.d.ts [22m[32m74.00 B[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m483.00 B[39m
|
|
23
|
+
[32mDTS[39m [1mdist/unsupported.d.mts [22m[32m74.00 B[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @wrelik/db
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a38ebcb: Add React Native / Expo support and enforce server-only boundaries.
|
|
8
|
+
- Updated dependencies [a38ebcb]
|
|
9
|
+
- @wrelik/errors@0.2.0
|
|
10
|
+
|
|
11
|
+
## 0.1.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Update publishConfig to access:public for all packages.
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @wrelik/errors@0.1.1
|
|
18
|
+
|
|
3
19
|
## 0.1.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/dist/index.d.mts
ADDED
|
@@ -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.d.ts
ADDED
|
@@ -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,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.
|
|
3
|
+
"version": "0.1.2",
|
|
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.
|
|
16
|
+
"@wrelik/errors": "0.2.0"
|
|
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.
|
|
14
|
-
"@wrelik/tsconfig": "0.1.
|
|
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
|
+
);
|