@wild-framework/resources 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wild Framework contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # @wild-framework/resources
2
+
3
+ API resource transformation for [Wild Framework](https://github.com/your-org/wild-framework).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @wild-framework/resources
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { Resource } from "@wild-framework/resources";
15
+
16
+ class UserResource extends Resource<User> {
17
+ transform(user: User): Record<string, unknown> {
18
+ return { id: user.id, name: user.name };
19
+ }
20
+ }
21
+
22
+ UserResource.make(user); // single
23
+ UserResource.collection(users); // array
24
+ ```
25
+
26
+ ## License
27
+
28
+ MIT
@@ -0,0 +1,2 @@
1
+ export { Resource } from "./resource.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Resource } from "./resource.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Base class for API resources.
3
+ *
4
+ * Subclasses define a `transform()` method that converts a domain object
5
+ * into a plain JSON-safe object. The static `make()` and `collection()`
6
+ * methods handle instantiation and iteration.
7
+ *
8
+ * @example
9
+ * class UserResource extends Resource<User> {
10
+ * transform(user: User): Record<string, unknown> {
11
+ * return { id: user.id, name: user.name };
12
+ * }
13
+ * }
14
+ *
15
+ * UserResource.make(user);
16
+ * UserResource.collection(users);
17
+ */
18
+ export declare abstract class Resource<T> {
19
+ /**
20
+ * Transform a single item into a plain object.
21
+ */
22
+ abstract transform(item: T): Record<string, unknown>;
23
+ /**
24
+ * Transform a single item.
25
+ *
26
+ * Instantiates the resource class and calls `transform()`.
27
+ */
28
+ static make<T>(this: new () => Resource<T>, item: T): Record<string, unknown>;
29
+ /**
30
+ * Transform an array of items.
31
+ *
32
+ * Calls `make()` for each item.
33
+ */
34
+ static collection<T>(this: new () => Resource<T>, items: T[]): Record<string, unknown>[];
35
+ }
36
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,8BAAsB,QAAQ,CAAC,CAAC;IAC5B;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAEpD;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAK7E;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;CAI3F"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Base class for API resources.
3
+ *
4
+ * Subclasses define a `transform()` method that converts a domain object
5
+ * into a plain JSON-safe object. The static `make()` and `collection()`
6
+ * methods handle instantiation and iteration.
7
+ *
8
+ * @example
9
+ * class UserResource extends Resource<User> {
10
+ * transform(user: User): Record<string, unknown> {
11
+ * return { id: user.id, name: user.name };
12
+ * }
13
+ * }
14
+ *
15
+ * UserResource.make(user);
16
+ * UserResource.collection(users);
17
+ */
18
+ export class Resource {
19
+ /**
20
+ * Transform a single item.
21
+ *
22
+ * Instantiates the resource class and calls `transform()`.
23
+ */
24
+ static make(item) {
25
+ const instance = new this();
26
+ return instance.transform(item);
27
+ }
28
+ /**
29
+ * Transform an array of items.
30
+ *
31
+ * Calls `make()` for each item.
32
+ */
33
+ static collection(items) {
34
+ const Ctor = this;
35
+ return items.map((item) => Ctor.make(item));
36
+ }
37
+ }
38
+ //# sourceMappingURL=resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAgB,QAAQ;IAM1B;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAiC,IAAO;QAC/C,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC;QAC5B,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAiC,KAAU;QACxD,MAAM,IAAI,GAAG,IAA6D,CAAC;QAC3E,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,CAAC;CACJ"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@wild-framework/resources",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Sphah",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/KhandaSoftware/wild-framework.git"
24
+ },
25
+ "description": "API resource transformation for Wild Framework.",
26
+ "keywords": [
27
+ "wild",
28
+ "framework",
29
+ "resources",
30
+ "api",
31
+ "transform"
32
+ ],
33
+ "scripts": {
34
+ "build": "tsc",
35
+ "clean": "rm -rf dist",
36
+ "test": "vitest run"
37
+ }
38
+ }