Skip to content

Commit 744d1eb

Browse files
Get the build working
1 parent 1d741e5 commit 744d1eb

48 files changed

Lines changed: 1702 additions & 4960 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tasks/soukai/lib/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { Uuid } from './helpers/uuid';
2-
import uuid from './helpers/uuid';
3-
export default uuid;
1+
import User from './models/users/User';
2+
import Workspace from './models/soukai/Workspace';
3+
export declare function getWorkspaces(user: User): Promise<Workspace[]>;

tasks/soukai/lib/index.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4+
return new (P || (P = Promise))(function (resolve, reject) {
5+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8+
step((generator = generator.apply(thisArg, _arguments || [])).next());
9+
});
10+
};
211
var __importDefault = (this && this.__importDefault) || function (mod) {
312
return (mod && mod.__esModule) ? mod : { "default": mod };
413
};
514
Object.defineProperty(exports, "__esModule", { value: true });
6-
exports.Uuid = void 0;
7-
var uuid_1 = require("./helpers/uuid");
8-
Object.defineProperty(exports, "Uuid", { enumerable: true, get: function () { return uuid_1.Uuid; } });
9-
const uuid_2 = __importDefault(require("./helpers/uuid"));
10-
exports.default = uuid_2.default;
15+
exports.getWorkspaces = void 0;
16+
const Workspace_1 = __importDefault(require("./models/soukai/Workspace"));
17+
function getWorkspaces(user) {
18+
return __awaiter(this, void 0, void 0, function* () {
19+
const workspaces = [];
20+
for (const storage of user.storages) {
21+
workspaces.push(...(yield Workspace_1.default.from(storage).all()));
22+
}
23+
return workspaces;
24+
});
25+
}
26+
exports.getWorkspaces = getWorkspaces;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { MultiModelRelation, SingleModelRelation, Attributes } from 'soukai';
2+
import { SolidModel } from 'soukai-solid';
3+
import Task from './Task';
4+
import Workspace from './Workspace';
5+
export default class List extends SolidModel {
6+
static ldpContainer: boolean;
7+
static rdfContexts: {
8+
lifecycle: string;
9+
};
10+
static rdfsClasses: string[];
11+
static fields: {
12+
name: {
13+
type: "string";
14+
rdfProperty: string;
15+
required: boolean;
16+
};
17+
taskUrls: {
18+
type: "array";
19+
rdfProperty: string;
20+
items: {
21+
type: "key";
22+
};
23+
};
24+
};
25+
name: string;
26+
workspace: Workspace;
27+
tasks?: Task[];
28+
editable: boolean;
29+
get empty(): boolean;
30+
get length(): number;
31+
workspaceRelationship(): SingleModelRelation;
32+
tasksRelationship(): MultiModelRelation;
33+
createTask(attributes: Attributes): Promise<Task>;
34+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4+
return new (P || (P = Promise))(function (resolve, reject) {
5+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8+
step((generator = generator.apply(thisArg, _arguments || [])).next());
9+
});
10+
};
11+
var __importDefault = (this && this.__importDefault) || function (mod) {
12+
return (mod && mod.__esModule) ? mod : { "default": mod };
13+
};
14+
Object.defineProperty(exports, "__esModule", { value: true });
15+
const soukai_1 = require("soukai");
16+
const soukai_solid_1 = require("soukai-solid");
17+
const Task_1 = __importDefault(require("./Task"));
18+
const Workspace_1 = __importDefault(require("./Workspace"));
19+
const AsyncOperation_1 = __importDefault(require("../../utils/AsyncOperation"));
20+
class List extends soukai_solid_1.SolidModel {
21+
constructor() {
22+
super(...arguments);
23+
this.editable = true;
24+
}
25+
get empty() {
26+
return this.isRelationLoaded('tasks') ? this.tasks.length === 0 : true;
27+
}
28+
get length() {
29+
return this.isRelationLoaded('tasks') ? this.tasks.length : 0;
30+
}
31+
workspaceRelationship() {
32+
return this.isContainedBy(Workspace_1.default);
33+
}
34+
tasksRelationship() {
35+
return this.hasMany(Task_1.default, 'taskUrls');
36+
}
37+
createTask(attributes) {
38+
return __awaiter(this, void 0, void 0, function* () {
39+
// TODO implement this.tasksRelationship().create(attributes); in soukai
40+
const task = new Task_1.default(attributes);
41+
const operation = new AsyncOperation_1.default(task.updatesListener);
42+
try {
43+
operation.start();
44+
if (this.isRelationLoaded('tasks')) {
45+
this.setRelationModels('tasks', [...this.tasks || [], task]);
46+
}
47+
yield task.save(this.url);
48+
yield this.update({ taskUrls: [...this.taskUrls, task.url] });
49+
operation.complete();
50+
return task;
51+
}
52+
catch (error) {
53+
operation.fail(error);
54+
const index = (this.tasks || []).indexOf(task);
55+
if (index !== -1) {
56+
const tasks = [...this.tasks];
57+
tasks.splice(index, 1);
58+
this.setRelationModels('tasks', tasks);
59+
}
60+
throw error;
61+
}
62+
});
63+
}
64+
}
65+
exports.default = List;
66+
List.ldpContainer = true;
67+
List.rdfContexts = {
68+
'lifecycle': 'http://purl.org/vocab/lifecycle/schema#',
69+
};
70+
List.rdfsClasses = ['lifecycle:TaskGroup'];
71+
List.fields = {
72+
name: {
73+
type: soukai_1.FieldType.String,
74+
rdfProperty: 'rdfs:label',
75+
required: true,
76+
},
77+
taskUrls: {
78+
type: soukai_1.FieldType.Array,
79+
rdfProperty: 'lifecycle:task',
80+
items: { type: soukai_1.FieldType.Key },
81+
},
82+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { SolidModel } from 'soukai-solid';
2+
import { Listener as AsyncOperationListener } from '../../utils/AsyncOperation';
3+
export default class Task extends SolidModel {
4+
static rdfContexts: {
5+
lifecycle: string;
6+
cal: string;
7+
};
8+
static rdfsClasses: string[];
9+
static fields: {
10+
name: {
11+
type: "string";
12+
rdfProperty: string;
13+
required: boolean;
14+
};
15+
description: {
16+
type: "string";
17+
rdfProperty: string;
18+
};
19+
priority: {
20+
type: "number";
21+
rdfProperty: string;
22+
};
23+
dueAt: {
24+
type: "date";
25+
rdfProperty: string;
26+
};
27+
completedAt: {
28+
type: "date";
29+
rdfProperty: string;
30+
};
31+
};
32+
saving: boolean;
33+
get completed(): boolean;
34+
get starred(): boolean;
35+
get updatesListener(): AsyncOperationListener;
36+
toggleCompleted(): void;
37+
toggleStarred(): void;
38+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const soukai_1 = require("soukai");
4+
const soukai_solid_1 = require("soukai-solid");
5+
class Task extends soukai_solid_1.SolidModel {
6+
constructor() {
7+
super(...arguments);
8+
this.saving = false;
9+
}
10+
get completed() {
11+
return !!this.completedAt;
12+
}
13+
get starred() {
14+
return !!this.priority && this.priority > 0;
15+
}
16+
get updatesListener() {
17+
return {
18+
onDelayed: () => this.saving = true,
19+
onCompleted: () => this.saving = false,
20+
onFailed: () => this.saving = false,
21+
};
22+
}
23+
toggleCompleted() {
24+
this.completed
25+
? delete this.completedAt
26+
: this.completedAt = new Date;
27+
}
28+
toggleStarred() {
29+
this.starred
30+
? delete this.priority
31+
: this.priority = 1;
32+
}
33+
}
34+
exports.default = Task;
35+
Task.rdfContexts = {
36+
'lifecycle': 'http://purl.org/vocab/lifecycle/schema#',
37+
'cal': 'http://www.w3.org/2002/12/cal/ical#',
38+
};
39+
Task.rdfsClasses = ['lifecycle:Task'];
40+
Task.fields = {
41+
name: {
42+
type: soukai_1.FieldType.String,
43+
rdfProperty: 'rdfs:label',
44+
required: true,
45+
},
46+
description: {
47+
type: soukai_1.FieldType.String,
48+
rdfProperty: 'rdfs:comment',
49+
},
50+
priority: {
51+
type: soukai_1.FieldType.Number,
52+
rdfProperty: 'cal:priority',
53+
},
54+
dueAt: {
55+
type: soukai_1.FieldType.Date,
56+
rdfProperty: 'cal:due',
57+
},
58+
completedAt: {
59+
type: soukai_1.FieldType.Date,
60+
rdfProperty: 'cal:completed',
61+
},
62+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { MultiModelRelation, Attributes, Model } from 'soukai';
2+
import { SolidModel } from 'soukai-solid';
3+
import List from './List';
4+
export default class Workspace extends SolidModel {
5+
static ldpContainer: boolean;
6+
static rdfContexts: {
7+
lifecycle: string;
8+
};
9+
static rdfsClasses: string[];
10+
static fields: {
11+
name: {
12+
type: "string";
13+
rdfProperty: string;
14+
required: boolean;
15+
};
16+
};
17+
static classFields: string[];
18+
inbox: List;
19+
lists?: List[];
20+
activeList: List;
21+
setActiveList(list: List): void;
22+
listsRelationship(): MultiModelRelation;
23+
save<T extends Model>(containerUrl?: string): Promise<T>;
24+
protected initialize(attributes: Attributes, exists: boolean): void;
25+
private updateInbox;
26+
private setInbox;
27+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4+
return new (P || (P = Promise))(function (resolve, reject) {
5+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8+
step((generator = generator.apply(thisArg, _arguments || [])).next());
9+
});
10+
};
11+
var __importDefault = (this && this.__importDefault) || function (mod) {
12+
return (mod && mod.__esModule) ? mod : { "default": mod };
13+
};
14+
Object.defineProperty(exports, "__esModule", { value: true });
15+
const soukai_1 = require("soukai");
16+
const soukai_solid_1 = require("soukai-solid");
17+
const List_1 = __importDefault(require("./List"));
18+
const decorators_1 = require("../../utils/decorators");
19+
const Storage_1 = __importDefault(require("../../utils/Storage"));
20+
class Workspace extends soukai_solid_1.SolidModel {
21+
setActiveList(list) {
22+
this.activeList = list;
23+
Storage_1.default.set('activeListId', list.id);
24+
}
25+
listsRelationship() {
26+
return this.contains(List_1.default);
27+
}
28+
save(containerUrl) {
29+
const _super = Object.create(null, {
30+
save: { get: () => super.save }
31+
});
32+
return __awaiter(this, void 0, void 0, function* () {
33+
const model = yield _super.save.call(this, containerUrl);
34+
if (!this.inbox.exists()) {
35+
const list = (yield List_1.default.find(this.url));
36+
list.setRelationModels('tasks', []);
37+
this.setInbox(list);
38+
}
39+
return model;
40+
});
41+
}
42+
initialize(attributes, exists) {
43+
super.initialize(attributes, exists);
44+
const list = new List_1.default(this.getAttributes(), false);
45+
list.setRelationModels('tasks', []);
46+
this.setInbox(list);
47+
if (this.exists()) {
48+
this.updateInbox();
49+
}
50+
}
51+
updateInbox() {
52+
return __awaiter(this, void 0, void 0, function* () {
53+
const list = yield List_1.default.find(this.getAttribute('url'));
54+
this.setInbox(list);
55+
});
56+
}
57+
setInbox(list) {
58+
const inbox = (0, decorators_1.decorate)(list, {
59+
getters: {
60+
name: () => 'Inbox',
61+
},
62+
});
63+
inbox.editable = false;
64+
inbox.setRelationModels('workspace', this);
65+
if (!this.activeList || this.activeList === this.inbox) {
66+
this.activeList = inbox;
67+
}
68+
this.inbox = inbox;
69+
}
70+
}
71+
exports.default = Workspace;
72+
Workspace.ldpContainer = true;
73+
Workspace.rdfContexts = {
74+
'lifecycle': 'http://purl.org/vocab/lifecycle/schema#',
75+
};
76+
Workspace.rdfsClasses = ['lifecycle:TaskGroup'];
77+
Workspace.fields = {
78+
name: {
79+
type: soukai_1.FieldType.String,
80+
rdfProperty: 'rdfs:label',
81+
required: true,
82+
},
83+
};
84+
Workspace.classFields = ['inbox', 'activeList'];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default abstract class User {
2+
name: string;
3+
avatarUrl: string | null;
4+
storages: string[];
5+
constructor(name: string, avatarUrl: string | null, storages: string[]);
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
class User {
4+
constructor(name, avatarUrl, storages) {
5+
this.name = name;
6+
this.avatarUrl = avatarUrl;
7+
this.storages = storages;
8+
}
9+
}
10+
exports.default = User;

0 commit comments

Comments
 (0)