dep-vcs 0.0.3 → 0.0.5

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/bin/dep.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * dep - Simple version control
5
- * CLI Binary (v0.0.1)
4
+ * dep - Efficient version control.
5
+ * CLI (v0.0.5)
6
6
  */
7
7
 
8
8
  const dep = require('../index.js');
@@ -1,6 +1,6 @@
1
1
  /**
2
- * dep - Simple version control
3
- * Module: Branching (v0.0.1)
2
+ * dep - Efficient version control.
3
+ * Module: Branching (v0.0.5)
4
4
  */
5
5
 
6
6
  const fs = require('fs');
@@ -133,7 +133,7 @@ function merge (targetBranch) {
133
133
  }
134
134
 
135
135
  module.exports = {
136
- __libraryVersion: '0.0.1',
136
+ __libraryVersion: '0.0.5',
137
137
  __libraryAPIName: 'Branching',
138
138
  branch,
139
139
  checkout,
package/caches/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
- * dep - Simple version control
3
- * Module: Caches (v0.0.1)
2
+ * dep - Efficient version control.
3
+ * Module: Caches (v0.0.5)
4
4
  */
5
5
 
6
6
  const fs = require('fs');
7
7
  const path = require('path');
8
8
 
9
- const { checkout } = require('../Branching/index.js');
9
+ const { checkout } = require('../branching/index.js');
10
10
 
11
11
  /**
12
12
  * Moves stage.json to a cache folder, or restores the most recent stash.
@@ -154,7 +154,7 @@ function rm (filePath) {
154
154
  }
155
155
 
156
156
  module.exports = {
157
- __libraryVersion: '0.0.1',
157
+ __libraryVersion: '0.0.5',
158
158
  __libraryAPIName: 'Caches',
159
159
  stash,
160
160
  reset,
package/changes/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * dep - Simple version control
3
- * Module: Changes (v0.0.1)
2
+ * dep - Efficient version control.
3
+ * Module: Changes (v0.0.5)
4
4
  */
5
5
 
6
6
  const fs = require('fs');
@@ -113,7 +113,7 @@ function diff () {
113
113
  }
114
114
 
115
115
  module.exports = {
116
- __libraryVersion: '0.0.1',
116
+ __libraryVersion: '0.0.5',
117
117
  __libraryAPIName: 'Changes',
118
118
  log,
119
119
  diff
@@ -1,21 +1,19 @@
1
1
  /**
2
- * dep - Simple version control
3
- * Module: Contributions (v0.0.1)
2
+ * dep - Efficient version control.
3
+ * Module: Contributions (v0.0.5)
4
4
  */
5
5
 
6
6
  const fs = require('fs');
7
7
  const path = require('path');
8
- const pkg = require('../package.json');
9
8
 
10
- const { checkout } = require('../Branching/index.js');
9
+ const pkg = require('../package.json');
10
+ const { checkout } = require('../branching/index.js');
11
11
 
12
12
  const DEP_HOST = pkg.depConfig.host || 'http://localhost:1337';
13
13
 
14
14
  /**
15
15
  * Configures the single URL endpoint in dep.json for synchronization.
16
- * Supports full URLs or "userName/repoName" slugs.
17
- * @param {string} input - The remote endpoint or slug.
18
- * @returns {string} The current remote URL.
16
+ * Supports full URLs or "handle/repo" slugs.
19
17
  */
20
18
 
21
19
  function remote (input) {
@@ -31,7 +29,7 @@ function remote (input) {
31
29
  let finalUrl = input;
32
30
 
33
31
  if (input.includes('/') && !input.startsWith('http')) {
34
- finalUrl = `${DEP_HOST}/code/${input}`;
32
+ finalUrl = `${DEP_HOST}/${input}`;
35
33
  }
36
34
 
37
35
  manifest.remote = finalUrl;
@@ -42,8 +40,7 @@ function remote (input) {
42
40
  }
43
41
 
44
42
  /**
45
- * Downloads JSON diff files from the remote server into history/remote.
46
- * @returns {Promise<string>} Result message.
43
+ * Downloads JSON diff files from the remote server via POST.
47
44
  */
48
45
 
49
46
  async function fetchRemote () {
@@ -55,20 +52,50 @@ async function fetchRemote () {
55
52
  }
56
53
 
57
54
  const branch = depJson.active.branch;
55
+ const token = depJson.configuration.personalAccessToken;
56
+
57
+ const remoteParts = depJson.remote.split('/');
58
+ const repo = remoteParts.pop();
59
+ const handle = remoteParts.pop();
60
+
58
61
  const remoteBranchPath = path.join(depPath, 'history/remote', branch);
59
62
 
60
63
  if (!fs.existsSync(remoteBranchPath)) {
61
64
  fs.mkdirSync(remoteBranchPath, { recursive: true });
62
65
  }
63
66
 
64
- const response = await fetch(`${depJson.remote}/history/remote/${branch}/manifest.json`);
67
+ const response = await fetch(`${DEP_HOST}/manifest`, {
68
+ method: 'POST',
69
+ headers: { 'Content-Type': 'application/json' },
70
+ body: JSON.stringify({
71
+ type: 'history',
72
+ handle,
73
+ repo,
74
+ branch,
75
+
76
+ ...(token && { personalAccessToken: token })
77
+ })
78
+ });
79
+
65
80
  const remoteManifest = await response.json();
66
81
 
67
82
  for (const commitHash of remoteManifest.commits) {
68
83
  const commitFilePath = path.join(remoteBranchPath, `${commitHash}.json`);
69
84
 
70
85
  if (!fs.existsSync(commitFilePath)) {
71
- const commitResponse = await fetch(`${depJson.remote}/history/remote/${branch}/${commitHash}.json`);
86
+ const commitResponse = await fetch(`${DEP_HOST}/commit`, {
87
+ method: 'POST',
88
+ headers: { 'Content-Type': 'application/json' },
89
+ body: JSON.stringify({
90
+ handle,
91
+ repo,
92
+ branch,
93
+ hash: commitHash,
94
+
95
+ ...(token && { personalAccessToken: token })
96
+ })
97
+ });
98
+
72
99
  const commitDiff = await commitResponse.json();
73
100
 
74
101
  fs.writeFileSync(commitFilePath, JSON.stringify(commitDiff, null, 2));
@@ -137,9 +164,27 @@ async function push () {
137
164
  }
138
165
 
139
166
  const branch = depJson.active.branch;
167
+ const token = depJson.configuration.personalAccessToken;
168
+
169
+ const remoteParts = depJson.remote.split('/');
170
+ const repo = remoteParts.pop();
171
+ const handle = remoteParts.pop();
172
+
140
173
  const localManifest = JSON.parse(fs.readFileSync(path.join(depPath, 'history/local', branch, 'manifest.json'), 'utf8'));
141
174
 
142
- const response = await fetch(`${depJson.remote}/history/remote/${branch}/manifest.json`);
175
+ const response = await fetch(`${DEP_HOST}/manifest`, {
176
+ method: 'POST',
177
+ headers: { 'Content-Type': 'application/json' },
178
+ body: JSON.stringify({
179
+ type: 'history',
180
+ handle,
181
+ repo,
182
+ branch,
183
+
184
+ ...(token && { personalAccessToken: token })
185
+ })
186
+ });
187
+
143
188
  const remoteManifest = await response.json();
144
189
 
145
190
  const missingCommits = localManifest.commits.filter(hash => !remoteManifest.commits.includes(hash));
@@ -151,12 +196,16 @@ async function push () {
151
196
  for (const commitHash of missingCommits) {
152
197
  const commitData = JSON.parse(fs.readFileSync(path.join(depPath, 'history/local', branch, `${commitHash}.json`), 'utf8'));
153
198
 
154
- await fetch(`${depJson.remote}/source/push`, {
199
+ await fetch(`${DEP_HOST}/push`, {
155
200
  method: 'POST',
156
201
  headers: { 'Content-Type': 'application/json' },
157
202
  body: JSON.stringify({
158
- branch: branch,
159
- commit: commitData
203
+ handle,
204
+ repo,
205
+ branch,
206
+ commit: commitData,
207
+
208
+ ...(token && { personalAccessToken: token })
160
209
  })
161
210
  });
162
211
  }
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * dep - Simple version control
3
- * Core Library Entry Point (v0.0.1)
2
+ * dep - Efficient version control.
3
+ * Core Library Entry Point (v0.0.5)
4
4
  */
5
5
 
6
6
  const Setup = require('./setup');
@@ -50,7 +50,7 @@ const dep = {
50
50
 
51
51
  // Metadata
52
52
 
53
- version: '0.0.1',
53
+ version: '0.0.5',
54
54
  modules: [
55
55
  Setup.__libraryAPIName,
56
56
  Workflow.__libraryAPIName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dep-vcs",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Efficient version control.",
5
5
  "main": "index.js",
6
6
  "bin": {
package/setup/index.js CHANGED
@@ -1,18 +1,17 @@
1
1
  /**
2
- * dep - Simple version control
3
- * Module: Setup (v0.0.1)
2
+ * dep - Efficient version control.
3
+ * Module: Setup (v0.0.5)
4
4
  */
5
5
 
6
6
  const fs = require('fs');
7
7
  const path = require('path');
8
8
 
9
9
  const pkg = require('../package.json');
10
+
10
11
  const DEP_HOST = pkg.depConfig.host || 'http://localhost:1337';
11
12
 
12
13
  /**
13
14
  * Initializes the local .dep directory structure.
14
- * @param {string} directoryPath - The path where the repository should be initialized.
15
- * @returns {string} A message indicating the result of the operation.
16
15
  */
17
16
 
18
17
  function init (directoryPath = process.cwd()) {
@@ -20,7 +19,7 @@ function init (directoryPath = process.cwd()) {
20
19
 
21
20
  const folders = [
22
21
  '',
23
- 'data',
22
+ 'root',
24
23
  'history',
25
24
  'history/local',
26
25
  'history/local/main',
@@ -41,15 +40,13 @@ function init (directoryPath = process.cwd()) {
41
40
  }
42
41
 
43
42
  const files = fs.readdirSync(directoryPath).filter(f => f !== '.dep');
44
-
45
- const dataManifest = {
46
- files: []
47
- };
43
+ const rootManifest = { files: [] };
48
44
 
49
45
  for (const file of files) {
50
46
  const fullPath = path.join(directoryPath, file);
47
+
51
48
  if (fs.lstatSync(fullPath).isFile()) {
52
- dataManifest.files.push({
49
+ rootManifest.files.push({
53
50
  path: file,
54
51
  content: fs.readFileSync(fullPath, 'utf8')
55
52
  });
@@ -57,28 +54,19 @@ function init (directoryPath = process.cwd()) {
57
54
  }
58
55
 
59
56
  fs.writeFileSync(
60
- path.join(depDirectory, 'data/manifest.json'),
61
- JSON.stringify(dataManifest, null, 2)
57
+ path.join(depDirectory, 'root/manifest.json'),
58
+ JSON.stringify(rootManifest, null, 2)
62
59
  );
63
60
 
64
- const historyManifest = {
65
- commits: []
66
- };
67
-
68
61
  fs.writeFileSync(
69
62
  path.join(depDirectory, 'history/local/main/manifest.json'),
70
- JSON.stringify(historyManifest, null, 2)
63
+ JSON.stringify({ commits: [] }, null, 2)
71
64
  );
72
65
 
73
66
  const depFile = {
74
- active: {
75
- branch: 'main',
76
- parent: null
77
- },
67
+ active: { branch: 'main', parent: null },
78
68
  remote: '',
79
- configuration: {
80
- userName: ''
81
- }
69
+ configuration: { handle: '', personalAccessToken: '' }
82
70
  };
83
71
 
84
72
  fs.writeFileSync(
@@ -90,9 +78,7 @@ function init (directoryPath = process.cwd()) {
90
78
  }
91
79
 
92
80
  /**
93
- * Clones a repository, populates "data", and replays "history".
94
- * @param {string} repoSlug - The "userName/repoName" slug.
95
- * @returns {Promise<string>}
81
+ * Clones a repository by fetching manifests and commits via POST.
96
82
  */
97
83
 
98
84
  async function clone (repoSlug) {
@@ -100,8 +86,8 @@ async function clone (repoSlug) {
100
86
  throw new Error('A valid slug is required.');
101
87
  }
102
88
 
103
- const [userName, repoName] = repoSlug.split('/');
104
- const targetPath = path.join(process.cwd(), repoName);
89
+ const [handle, repo] = repoSlug.split('/');
90
+ const targetPath = path.join(process.cwd(), repo);
105
91
  const depPath = path.join(targetPath, '.dep');
106
92
 
107
93
  if (fs.existsSync(targetPath)) {
@@ -111,27 +97,65 @@ async function clone (repoSlug) {
111
97
  fs.mkdirSync(targetPath);
112
98
  init(targetPath);
113
99
 
114
- const dataRes = await fetch(`${DEP_HOST}/${userName}/${repoName}/data/manifest.json`);
115
- const dataManifest = await dataRes.json();
100
+ const depJson = JSON.parse(fs.readFileSync(path.join(depPath, 'dep.json'), 'utf8'));
101
+ const token = depJson.configuration.personalAccessToken;
102
+
103
+ const rootRes = await fetch(`${DEP_HOST}/manifest`, {
104
+ method: 'POST',
105
+ headers: { 'Content-Type': 'application/json' },
106
+ body: JSON.stringify({
107
+ type: 'root',
108
+ handle,
109
+ repo,
110
+ branch: 'main',
116
111
 
117
- if (dataManifest.files) {
118
- for (const file of dataManifest.files) {
119
- const internalDataPath = path.join(depPath, 'data', file.path);
112
+ ...(token && { personalAccessToken: token })
113
+ })
114
+ });
115
+
116
+ const rootManifest = await rootRes.json();
117
+
118
+ if (rootManifest.files) {
119
+ for (const file of rootManifest.files) {
120
+ const internalRootPath = path.join(depPath, 'root', file.path);
120
121
  const workingPath = path.join(targetPath, file.path);
121
122
 
122
- fs.mkdirSync(path.dirname(internalDataPath), { recursive: true });
123
- fs.writeFileSync(internalDataPath, file.content);
123
+ fs.mkdirSync(path.dirname(internalRootPath), { recursive: true });
124
+ fs.writeFileSync(internalRootPath, file.content);
124
125
  fs.writeFileSync(workingPath, file.content);
125
126
  }
126
127
  }
127
128
 
128
- const historyUrl = `${DEP_HOST}/${userName}/${repoName}/history/remote/main/manifest.json`;
129
- const historyRes = await fetch(historyUrl);
129
+ const historyRes = await fetch(`${DEP_HOST}/manifest`, {
130
+ method: 'POST',
131
+ headers: { 'Content-Type': 'application/json' },
132
+ body: JSON.stringify({
133
+ type: 'history',
134
+ handle,
135
+ repo,
136
+ branch: 'main',
137
+
138
+ ...(token && { personalAccessToken: token })
139
+ })
140
+ });
141
+
130
142
  const historyManifest = await historyRes.json();
131
143
 
132
144
  if (historyManifest.commits) {
133
145
  for (const commitHash of historyManifest.commits) {
134
- const commitRes = await fetch(`${DEP_HOST}/${userName}/${repoName}/history/remote/main/${commitHash}.json`);
146
+ const commitRes = await fetch(`${DEP_HOST}/commit`, {
147
+ method: 'POST',
148
+ headers: { 'Content-Type': 'application/json' },
149
+ body: JSON.stringify({
150
+ handle,
151
+ repo,
152
+ branch: 'main',
153
+ hash: commitHash,
154
+
155
+ ...(token && { personalAccessToken: token })
156
+ })
157
+ });
158
+
135
159
  const commitDiff = await commitRes.json();
136
160
 
137
161
  for (const filePath of Object.keys(commitDiff.changes)) {
@@ -139,23 +163,19 @@ async function clone (repoSlug) {
139
163
  const changeSet = commitDiff.changes[filePath];
140
164
 
141
165
  if (Array.isArray(changeSet)) {
142
- let currentContent = fs.existsSync(fullPath)
143
- ? fs.readFileSync(fullPath, 'utf8')
144
- : '';
166
+ let currentContent = fs.existsSync(fullPath) ? fs.readFileSync(fullPath, 'utf8') : '';
145
167
 
146
168
  for (const operation of changeSet) {
147
169
  if (operation.type === 'insert') {
148
- currentContent = `${currentContent.slice(0, operation.position)}${operation.content}${currentContent.slice(operation.position)}`;
170
+ currentContent = currentContent.slice(0, operation.position) + operation.content + currentContent.slice(operation.position);
149
171
  } else if (operation.type === 'delete') {
150
- currentContent = `${currentContent.slice(0, operation.position)}${currentContent.slice(operation.position + operation.length)}`;
172
+ currentContent = currentContent.slice(0, operation.position) + currentContent.slice(operation.position + operation.length);
151
173
  }
152
174
  }
153
175
 
154
176
  fs.writeFileSync(fullPath, currentContent);
155
177
  } else if (changeSet.type === 'deleteFile') {
156
- if (fs.existsSync(fullPath)) {
157
- fs.unlinkSync(fullPath);
158
- }
178
+ if (fs.existsSync(fullPath)) fs.unlinkSync(fullPath);
159
179
  } else if (changeSet.type === 'createFile') {
160
180
  fs.writeFileSync(fullPath, changeSet.content || '');
161
181
  }
@@ -186,6 +206,7 @@ function config (key, value) {
186
206
 
187
207
  if (key && value !== undefined) {
188
208
  manifest.configuration[key] = value;
209
+
189
210
  fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
190
211
  }
191
212
 
@@ -1,6 +1,6 @@
1
1
  /**
2
- * dep - Simple version control
3
- * Module: Utils (v0.0.1)
2
+ * dep - Efficient version control.
3
+ * Module: Utils (v0.0.5)
4
4
  */
5
5
 
6
6
  const fs = require('fs');
@@ -12,36 +12,37 @@ const path = require('path');
12
12
 
13
13
  module.exports = (branchName, targetHash) => {
14
14
  const depPath = path.join(process.cwd(), '.dep');
15
- const dataPath = path.join(depPath, 'data/manifest.json');
15
+ const rootPath = path.join(depPath, 'root/manifest.json');
16
16
 
17
- if (!fs.existsSync(dataPath)) return {};
17
+ if (!fs.existsSync(rootPath)) return {};
18
18
 
19
- const dataManifest = JSON.parse(fs.readFileSync(dataPath, 'utf8'));
19
+ const rootManifest = JSON.parse(fs.readFileSync(rootPath, 'utf8'));
20
20
  const branchPath = path.join(depPath, 'history/local', branchName);
21
21
  const manifestPath = path.join(branchPath, 'manifest.json');
22
22
 
23
23
  if (!fs.existsSync(manifestPath)) return {};
24
24
 
25
25
  const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
26
+
26
27
  let state = {};
27
28
 
28
- for (const file of dataManifest.files) {
29
- state[file.path] = file.content;
29
+ for (const file of rootManifest.files) {
30
+ state[file.path] = file.content;
30
31
  }
31
32
 
32
33
  for (const hash of manifest.commits) {
33
- const commitPath = path.join(branchPath, `${hash}.json`);
34
- const commit = JSON.parse(fs.readFileSync(commitPath, 'utf8'));
35
-
36
- for (const [filePath, change] of Object.entries(commit.changes)) {
37
- if (change.type === 'createFile' || change.type === 'update') {
38
- state[filePath] = change.content;
39
- } else if (change.type === 'deleteFile') {
40
- delete state[filePath];
41
- }
42
- }
43
-
44
- if (hash === targetHash) break;
34
+ const commitPath = path.join(branchPath, `${hash}.json`);
35
+ const commit = JSON.parse(fs.readFileSync(commitPath, 'utf8'));
36
+
37
+ for (const [filePath, change] of Object.entries(commit.changes)) {
38
+ if (change.type === 'createFile' || change.type === 'update') {
39
+ state[filePath] = change.content;
40
+ } else if (change.type === 'deleteFile') {
41
+ delete state[filePath];
42
+ }
43
+ }
44
+
45
+ if (hash === targetHash) break;
45
46
  }
46
47
 
47
48
  return state;
package/workflow/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * dep - Simple version control
3
- * Module: Workflow (v0.0.1)
2
+ * dep - Efficient version control.
3
+ * Module: Workflow (v0.0.5)
4
4
  */
5
5
 
6
6
  const fs = require('fs');
@@ -140,7 +140,7 @@ function commit (message) {
140
140
  }
141
141
 
142
142
  module.exports = {
143
- __libraryVersion: '0.0.1',
143
+ __libraryVersion: '0.0.5',
144
144
  __libraryAPIName: 'Workflow',
145
145
  status,
146
146
  add,