@xframework/t3-oss__env 0.4.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/.turbo/turbo-build.log +22 -0
- package/CHANGELOG.md +19 -0
- package/dist/index.cjs +41 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
- package/src/__tests__/index.test.ts +109 -0
- package/src/index.ts +16 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +3 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
> @xframework/t3-oss__env@0.4.1 build /home/runner/work/x/x/packages/@xframework/t3-oss__env
|
3
|
+
> tsup
|
4
|
+
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
7
|
+
[34mCLI[39m tsup v8.3.5
|
8
|
+
[34mCLI[39m Using tsup config: /home/runner/work/x/x/packages/@xframework/t3-oss__env/tsup.config.ts
|
9
|
+
[34mCLI[39m Target: esnext
|
10
|
+
[34mCLI[39m Cleaning output folder
|
11
|
+
[34mCJS[39m Build start
|
12
|
+
[34mESM[39m Build start
|
13
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m1.29 KB[39m
|
14
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m592.00 B[39m
|
15
|
+
[32mCJS[39m ⚡️ Build success in 29ms
|
16
|
+
[32mESM[39m [1mdist/index.js [22m[32m286.00 B[39m
|
17
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m552.00 B[39m
|
18
|
+
[32mESM[39m ⚡️ Build success in 30ms
|
19
|
+
[34mDTS[39m Build start
|
20
|
+
[32mDTS[39m ⚡️ Build success in 4847ms
|
21
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m249.00 B[39m
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m249.00 B[39m
|
package/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# @xframework/t3-oss\_\_env-core
|
2
|
+
|
3
|
+
## 0.4.1
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- fe37e1d: rename package
|
8
|
+
- @xframework/x@0.4.1
|
9
|
+
|
10
|
+
## 0.4.0
|
11
|
+
|
12
|
+
### Minor Changes
|
13
|
+
|
14
|
+
- 98dd8e4: redesign
|
15
|
+
|
16
|
+
### Patch Changes
|
17
|
+
|
18
|
+
- Updated dependencies [98dd8e4]
|
19
|
+
- @xframework/x@0.4.0
|
package/dist/index.cjs
ADDED
@@ -0,0 +1,41 @@
|
|
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
|
+
T3EnvAdapter: () => T3EnvAdapter
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
26
|
+
var import_adapter = require("@xframework/x/adapter");
|
27
|
+
var T3EnvAdapter = class extends import_adapter.SyncAdapter {
|
28
|
+
env;
|
29
|
+
constructor({ env }) {
|
30
|
+
super();
|
31
|
+
this.env = env;
|
32
|
+
}
|
33
|
+
export() {
|
34
|
+
return this.env;
|
35
|
+
}
|
36
|
+
};
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
38
|
+
0 && (module.exports = {
|
39
|
+
T3EnvAdapter
|
40
|
+
});
|
41
|
+
//# sourceMappingURL=index.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { SyncAdapter } from \"@xframework/x/adapter\";\n\nexport class T3EnvAdapter<\n T extends Record<string, unknown>,\n> extends SyncAdapter<T> {\n public env: T;\n\n constructor({ env }: { env: T }) {\n super();\n this.env = env;\n }\n\n export() {\n return this.env;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA4B;AAErB,IAAM,eAAN,cAEG,2BAAe;AAAA,EAChB;AAAA,EAEP,YAAY,EAAE,IAAI,GAAe;AAC/B,UAAM;AACN,SAAK,MAAM;AAAA,EACb;AAAA,EAEA,SAAS;AACP,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
// src/index.ts
|
2
|
+
import { SyncAdapter } from "@xframework/x/adapter";
|
3
|
+
var T3EnvAdapter = class extends SyncAdapter {
|
4
|
+
env;
|
5
|
+
constructor({ env }) {
|
6
|
+
super();
|
7
|
+
this.env = env;
|
8
|
+
}
|
9
|
+
export() {
|
10
|
+
return this.env;
|
11
|
+
}
|
12
|
+
};
|
13
|
+
export {
|
14
|
+
T3EnvAdapter
|
15
|
+
};
|
16
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { SyncAdapter } from \"@xframework/x/adapter\";\n\nexport class T3EnvAdapter<\n T extends Record<string, unknown>,\n> extends SyncAdapter<T> {\n public env: T;\n\n constructor({ env }: { env: T }) {\n super();\n this.env = env;\n }\n\n export() {\n return this.env;\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAErB,IAAM,eAAN,cAEG,YAAe;AAAA,EAChB;AAAA,EAEP,YAAY,EAAE,IAAI,GAAe;AAC/B,UAAM;AACN,SAAK,MAAM;AAAA,EACb;AAAA,EAEA,SAAS;AACP,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
package/package.json
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"name": "@xframework/t3-oss__env",
|
3
|
+
"version": "0.4.1",
|
4
|
+
"type": "module",
|
5
|
+
"exports": {
|
6
|
+
".": {
|
7
|
+
"types": "./dist/index.d.ts",
|
8
|
+
"require": "./dist/index.cjs",
|
9
|
+
"import": "./dist/index.js"
|
10
|
+
}
|
11
|
+
},
|
12
|
+
"main": "./dist/index.cjs",
|
13
|
+
"module": "./dist/index.js",
|
14
|
+
"types": "./dist/index.d.ts",
|
15
|
+
"publishConfig": {
|
16
|
+
"access": "public"
|
17
|
+
},
|
18
|
+
"dependencies": {
|
19
|
+
"@xframework/x": "0.4.1"
|
20
|
+
},
|
21
|
+
"peerDependencies": {
|
22
|
+
"@t3-oss/env-core": ">=0.12.0"
|
23
|
+
},
|
24
|
+
"devDependencies": {
|
25
|
+
"@t3-oss/env-core": "^0.12.0",
|
26
|
+
"@t3-oss/env-nextjs": "^0.12.0",
|
27
|
+
"@t3-oss/env-nuxt": "^0.12.0",
|
28
|
+
"@types/node": "^20.11.24",
|
29
|
+
"tsup": "^8.2.4",
|
30
|
+
"typescript": "^5.5.4",
|
31
|
+
"zod": "^3.22.4"
|
32
|
+
},
|
33
|
+
"scripts": {
|
34
|
+
"build": "tsup",
|
35
|
+
"dev": "tsup --watch"
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import { createEnv } from "@t3-oss/env-core";
|
2
|
+
import { createEnv as createNextEnv } from "@t3-oss/env-nextjs";
|
3
|
+
import { createEnv as createNuxtEnv } from "@t3-oss/env-nuxt";
|
4
|
+
import { expect, it } from "vitest";
|
5
|
+
import { createX } from "@xframework/x";
|
6
|
+
import { z } from "zod";
|
7
|
+
import { T3EnvAdapter } from "../index";
|
8
|
+
|
9
|
+
it("should work with basic env-core setup", () => {
|
10
|
+
// Create a basic env configuration
|
11
|
+
const env = createEnv({
|
12
|
+
server: {
|
13
|
+
DATABASE_URL: z.string().url(),
|
14
|
+
API_KEY: z.string().min(1),
|
15
|
+
},
|
16
|
+
runtimeEnv: {
|
17
|
+
DATABASE_URL: "postgresql://localhost:5432/mydb",
|
18
|
+
API_KEY: "secret-key",
|
19
|
+
},
|
20
|
+
skipValidation: true, // Skip for testing
|
21
|
+
});
|
22
|
+
|
23
|
+
const x = createX()
|
24
|
+
.syncAdapter("env", () => new T3EnvAdapter({ env }))
|
25
|
+
.build();
|
26
|
+
|
27
|
+
expect(x.env.DATABASE_URL).toBe("postgresql://localhost:5432/mydb");
|
28
|
+
expect(x.env.API_KEY).toBe("secret-key");
|
29
|
+
expect(x._.adapters.env).toBeInstanceOf(T3EnvAdapter);
|
30
|
+
});
|
31
|
+
|
32
|
+
it("should work with Next.js environment setup", () => {
|
33
|
+
// Create a Next.js-style env configuration
|
34
|
+
const env = createNextEnv({
|
35
|
+
server: {
|
36
|
+
NODE_ENV: z.enum(["development", "production", "test"]),
|
37
|
+
DATABASE_URL: z.string().url(),
|
38
|
+
},
|
39
|
+
client: {
|
40
|
+
NEXT_PUBLIC_API_URL: z.string().url(),
|
41
|
+
},
|
42
|
+
runtimeEnv: {
|
43
|
+
NODE_ENV: "development",
|
44
|
+
DATABASE_URL: "postgresql://localhost:5432/nextapp",
|
45
|
+
NEXT_PUBLIC_API_URL: "https://api.example.com",
|
46
|
+
},
|
47
|
+
skipValidation: true,
|
48
|
+
});
|
49
|
+
|
50
|
+
const x = createX()
|
51
|
+
.syncAdapter("env", () => new T3EnvAdapter({ env }))
|
52
|
+
.build();
|
53
|
+
|
54
|
+
expect(x.env.NODE_ENV).toBe("development");
|
55
|
+
expect(x.env.DATABASE_URL).toBe("postgresql://localhost:5432/nextapp");
|
56
|
+
expect(x.env.NEXT_PUBLIC_API_URL).toBe("https://api.example.com");
|
57
|
+
});
|
58
|
+
|
59
|
+
it("should work with Nuxt environment setup", () => {
|
60
|
+
// Create a Nuxt-style env configuration
|
61
|
+
const env = createNuxtEnv({
|
62
|
+
server: {
|
63
|
+
NUXT_API_SECRET: z.string(),
|
64
|
+
NUXT_MONGODB_URI: z.string().url(),
|
65
|
+
},
|
66
|
+
client: {
|
67
|
+
NUXT_PUBLIC_API_BASE: z.string().url(),
|
68
|
+
},
|
69
|
+
skipValidation: true, // Skip for testing
|
70
|
+
});
|
71
|
+
|
72
|
+
process.env.NUXT_API_SECRET = "super-secret";
|
73
|
+
process.env.NUXT_MONGODB_URI = "mongodb://localhost:27017/nuxtapp";
|
74
|
+
process.env.NUXT_PUBLIC_API_BASE = "https://api.nuxtapp.com";
|
75
|
+
|
76
|
+
const x = createX()
|
77
|
+
.syncAdapter("env", () => new T3EnvAdapter({ env }))
|
78
|
+
.build();
|
79
|
+
|
80
|
+
expect(x.env.NUXT_API_SECRET).toBe("super-secret");
|
81
|
+
expect(x.env.NUXT_MONGODB_URI).toBe("mongodb://localhost:27017/nuxtapp");
|
82
|
+
expect(x.env.NUXT_PUBLIC_API_BASE).toBe("https://api.nuxtapp.com");
|
83
|
+
});
|
84
|
+
|
85
|
+
it("should handle validation errors", () => {
|
86
|
+
expect(() => {
|
87
|
+
createEnv({
|
88
|
+
server: {
|
89
|
+
DATABASE_URL: z.string().url(),
|
90
|
+
},
|
91
|
+
runtimeEnv: {
|
92
|
+
DATABASE_URL: "not-a-valid-url", // This should fail validation
|
93
|
+
},
|
94
|
+
});
|
95
|
+
}).toThrow();
|
96
|
+
});
|
97
|
+
|
98
|
+
it("should handle missing required variables", () => {
|
99
|
+
expect(() => {
|
100
|
+
createEnv({
|
101
|
+
server: {
|
102
|
+
REQUIRED_VAR: z.string(),
|
103
|
+
},
|
104
|
+
runtimeEnv: {
|
105
|
+
// REQUIRED_VAR is missing
|
106
|
+
},
|
107
|
+
});
|
108
|
+
}).toThrow();
|
109
|
+
});
|
package/src/index.ts
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
import { SyncAdapter } from "@xframework/x/adapter";
|
2
|
+
|
3
|
+
export class T3EnvAdapter<
|
4
|
+
T extends Record<string, unknown>,
|
5
|
+
> extends SyncAdapter<T> {
|
6
|
+
public env: T;
|
7
|
+
|
8
|
+
constructor({ env }: { env: T }) {
|
9
|
+
super();
|
10
|
+
this.env = env;
|
11
|
+
}
|
12
|
+
|
13
|
+
export() {
|
14
|
+
return this.env;
|
15
|
+
}
|
16
|
+
}
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED