shadowly 1.0.1 → 1.0.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.
- package/LICENSE +6 -6
- package/package.json +2 -2
- package/dist/class.d.ts +0 -63
- package/dist/class.js +0 -172
- package/dist/error.d.ts +0 -4
- package/dist/error.js +0 -13
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -7
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2025 Pro203S
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2025 Pro203S
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shadowly",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "TypeScript JSON Database",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"database",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"author": "Pro203S",
|
|
21
|
-
"type": "
|
|
21
|
+
"type": "commonjs",
|
|
22
22
|
"main": "./dist/index.js",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsc"
|
package/dist/class.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
type GetKey<T> = T extends readonly any[] ? number : T extends object ? keyof T : never;
|
|
2
|
-
type GetValue<T, K> = T extends readonly (infer U)[] ? U : T extends Record<PropertyKey, any> ? (K extends keyof T ? T[K] : never) : never;
|
|
3
|
-
type RemoveKey<T> = T extends readonly any[] ? number : T extends object ? keyof T : never;
|
|
4
|
-
export default class Shadowly<TRoot, TNode = TRoot> {
|
|
5
|
-
readonly DB_PATH: string;
|
|
6
|
-
private readonly path;
|
|
7
|
-
private content;
|
|
8
|
-
private parent?;
|
|
9
|
-
private parentKey?;
|
|
10
|
-
/**
|
|
11
|
-
* Shadowly의 새 인스턴스를 만듭니다.
|
|
12
|
-
* @param path JSON 파일 경로
|
|
13
|
-
*/
|
|
14
|
-
constructor(path: string);
|
|
15
|
-
/**
|
|
16
|
-
* 새 JSON을 만듭니다.
|
|
17
|
-
* @param path JSON 파일 경로
|
|
18
|
-
* @param isArray true면 []를 쓰고, false면 {}를 씁니다.
|
|
19
|
-
*/
|
|
20
|
-
static generateNewJson(path: string, isArray?: boolean): void;
|
|
21
|
-
private static create;
|
|
22
|
-
/**
|
|
23
|
-
* key로 이동합니다.
|
|
24
|
-
* @param key 이동할 키 이름
|
|
25
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
26
|
-
*/
|
|
27
|
-
get<K extends GetKey<TNode>>(key: K): Shadowly<TRoot, GetValue<TNode, K>>;
|
|
28
|
-
/**
|
|
29
|
-
* 현재 key의 value를 반환합니다.
|
|
30
|
-
* @returns 현재 key의 value
|
|
31
|
-
*/
|
|
32
|
-
value(): TNode;
|
|
33
|
-
/**
|
|
34
|
-
* 현재 key에 값을 씁니다.
|
|
35
|
-
* @param value 쓸 값
|
|
36
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
37
|
-
*/
|
|
38
|
-
set(value: TNode): this;
|
|
39
|
-
/**
|
|
40
|
-
* key를 삭제합니다.
|
|
41
|
-
* @param key 삭제할 key
|
|
42
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
43
|
-
*/
|
|
44
|
-
remove<K extends RemoveKey<TNode>>(key: K): this;
|
|
45
|
-
/**
|
|
46
|
-
* 한 번 뒤로 이동합니다.
|
|
47
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
48
|
-
*/
|
|
49
|
-
back(): Shadowly<TRoot, any>;
|
|
50
|
-
/**
|
|
51
|
-
* steps만큼 뒤로 이동합니다.
|
|
52
|
-
* @param steps 이동할 횟수
|
|
53
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
54
|
-
*/
|
|
55
|
-
up(steps?: number): Shadowly<TRoot, any>;
|
|
56
|
-
/**
|
|
57
|
-
* JSON의 루트로 이동합니다.
|
|
58
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
59
|
-
*/
|
|
60
|
-
root(): Shadowly<TRoot, TRoot>;
|
|
61
|
-
private persist;
|
|
62
|
-
}
|
|
63
|
-
export {};
|
package/dist/class.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const fs = __importStar(require("node:fs"));
|
|
37
|
-
const error_1 = require("./error");
|
|
38
|
-
function isValidJson(text) {
|
|
39
|
-
if (typeof text !== "string")
|
|
40
|
-
return false;
|
|
41
|
-
try {
|
|
42
|
-
JSON.parse(text);
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
class Shadowly {
|
|
50
|
-
DB_PATH;
|
|
51
|
-
path;
|
|
52
|
-
content;
|
|
53
|
-
parent;
|
|
54
|
-
parentKey;
|
|
55
|
-
/**
|
|
56
|
-
* Shadowly의 새 인스턴스를 만듭니다.
|
|
57
|
-
* @param path JSON 파일 경로
|
|
58
|
-
*/
|
|
59
|
-
constructor(path) {
|
|
60
|
-
this.path = path;
|
|
61
|
-
this.DB_PATH = path;
|
|
62
|
-
if (!fs.existsSync(path))
|
|
63
|
-
throw new error_1.ShadowlyError("ENOTFOUND", path + " not found.");
|
|
64
|
-
const file = fs.readFileSync(path, "utf-8");
|
|
65
|
-
if (!isValidJson(file))
|
|
66
|
-
throw new error_1.ShadowlyError("EINVALID", path + " is not valid.");
|
|
67
|
-
this.content = JSON.parse(file);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* 새 JSON을 만듭니다.
|
|
71
|
-
* @param path JSON 파일 경로
|
|
72
|
-
* @param isArray true면 []를 쓰고, false면 {}를 씁니다.
|
|
73
|
-
*/
|
|
74
|
-
static generateNewJson(path, isArray) {
|
|
75
|
-
fs.writeFileSync(path, isArray ? "[]" : "{}", "utf-8");
|
|
76
|
-
}
|
|
77
|
-
static create(DB_PATH, path, content, parent, parentKey) {
|
|
78
|
-
const inst = Object.create(Shadowly.prototype);
|
|
79
|
-
inst.DB_PATH = DB_PATH;
|
|
80
|
-
inst.path = path;
|
|
81
|
-
inst.content = content;
|
|
82
|
-
inst.parent = parent;
|
|
83
|
-
inst.parentKey = parentKey;
|
|
84
|
-
return inst;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* key로 이동합니다.
|
|
88
|
-
* @param key 이동할 키 이름
|
|
89
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
90
|
-
*/
|
|
91
|
-
get(key) {
|
|
92
|
-
const nextContent = this.content[key];
|
|
93
|
-
return Shadowly.create(this.DB_PATH, this.path, nextContent, this, key);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* 현재 key의 value를 반환합니다.
|
|
97
|
-
* @returns 현재 key의 value
|
|
98
|
-
*/
|
|
99
|
-
value() {
|
|
100
|
-
return this.content;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* 현재 key에 값을 씁니다.
|
|
104
|
-
* @param value 쓸 값
|
|
105
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
106
|
-
*/
|
|
107
|
-
set(value) {
|
|
108
|
-
this.content = value;
|
|
109
|
-
if (this.parent && this.parentKey !== undefined) {
|
|
110
|
-
this.parent.content[this.parentKey] = value;
|
|
111
|
-
}
|
|
112
|
-
this.persist();
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* key를 삭제합니다.
|
|
117
|
-
* @param key 삭제할 key
|
|
118
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
119
|
-
*/
|
|
120
|
-
remove(key) {
|
|
121
|
-
const cur = this.content;
|
|
122
|
-
if (Array.isArray(cur)) {
|
|
123
|
-
const idx = key;
|
|
124
|
-
if (Number.isInteger(idx) && idx >= 0 && idx < cur.length)
|
|
125
|
-
cur.splice(idx, 1);
|
|
126
|
-
}
|
|
127
|
-
else if (cur && typeof cur === "object") {
|
|
128
|
-
delete cur[key];
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
throw new error_1.ShadowlyError("ETYPE", "Current value is not an object/array.");
|
|
132
|
-
}
|
|
133
|
-
this.persist();
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* 한 번 뒤로 이동합니다.
|
|
138
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
139
|
-
*/
|
|
140
|
-
back() {
|
|
141
|
-
return this.parent ?? this;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* steps만큼 뒤로 이동합니다.
|
|
145
|
-
* @param steps 이동할 횟수
|
|
146
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
147
|
-
*/
|
|
148
|
-
up(steps = 1) {
|
|
149
|
-
let cur = this;
|
|
150
|
-
for (let i = 0; i < steps; i++) {
|
|
151
|
-
if (!cur.parent)
|
|
152
|
-
break;
|
|
153
|
-
cur = cur.parent;
|
|
154
|
-
}
|
|
155
|
-
return cur;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* JSON의 루트로 이동합니다.
|
|
159
|
-
* @returns 작업 수행 후 Shadowly 인스턴스
|
|
160
|
-
*/
|
|
161
|
-
root() {
|
|
162
|
-
let cur = this;
|
|
163
|
-
while (cur.parent)
|
|
164
|
-
cur = cur.parent;
|
|
165
|
-
return cur;
|
|
166
|
-
}
|
|
167
|
-
persist() {
|
|
168
|
-
const r = this.root();
|
|
169
|
-
fs.writeFileSync(r.DB_PATH, JSON.stringify(r.content, null, 2), "utf-8");
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
exports.default = Shadowly;
|
package/dist/error.d.ts
DELETED
package/dist/error.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ShadowlyError = void 0;
|
|
4
|
-
class ShadowlyError extends Error {
|
|
5
|
-
code;
|
|
6
|
-
constructor(code, message) {
|
|
7
|
-
super(code + ": " + message);
|
|
8
|
-
this.name = "Shadowly";
|
|
9
|
-
this.code = code;
|
|
10
|
-
Error.captureStackTrace(this, this.constructor);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.ShadowlyError = ShadowlyError;
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const class_1 = __importDefault(require("./class"));
|
|
7
|
-
exports.default = class_1.default;
|