Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kizahasi/flocon-core

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kizahasi/flocon-core - npm Package Compare versions

Comparing version 0.9.2 to 0.10.0

dist/internal/ot/room/participant/imagePieceValue/v1.d.ts

2

dist/index.d.ts

@@ -20,3 +20,3 @@ export { Commands, CommandElement, parseToCommands, isValidVarToml, parseToml, applyCommands, getVariableFromVarTomlObject, generateChatPalette, } from './internal/flocommand';

export { ofOperation as toDicePieceValueLog, Main as DicePieceValueLog, updateType, createType, deleteType, } from './internal/ot/room/character/dicePieceValue/log-v1';
export { State as ImagePieceState, UpOperation as ImagePieceUpOperation, DownOperation as ImagePieceDownOperation, apply as applyImagePiece, diff as imagePieceDiff, toUpOperation as toImagePieceUpOperation, } from './internal/ot/room/board/imagePiece/v1';
export { State as ImagePieceState, UpOperation as ImagePieceUpOperation, DownOperation as ImagePieceDownOperation, apply as applyImagePiece, diff as imagePieceDiff, toUpOperation as toImagePieceUpOperation, } from './internal/ot/room/participant/imagePieceValue/v1';
export { State as NumberPieceValueState, UpOperation as NumberPieceValueUpOperation, DownOperation as NumberPieceValueDownOperation, apply as applyNumberPieceValue, diff as numberPieceValueDiff, toUpOperation as toNumberPieceValueUpOperation, } from './internal/ot/room/character/numberPieceValue/v1';

@@ -23,0 +23,0 @@ export { decode as decodeNumberPieceValue, parse as parseNumberPieceValue, exact as exactNumberPieceValue, } from './internal/ot/room/character/numberPieceValue/converter';

@@ -85,3 +85,3 @@ "use strict";

Object.defineProperty(exports, "deleteType", { enumerable: true, get: function () { return log_v1_1.deleteType; } });
var v1_11 = require("./internal/ot/room/board/imagePiece/v1");
var v1_11 = require("./internal/ot/room/participant/imagePieceValue/v1");
Object.defineProperty(exports, "applyImagePiece", { enumerable: true, get: function () { return v1_11.apply; } });

@@ -88,0 +88,0 @@ Object.defineProperty(exports, "imagePieceDiff", { enumerable: true, get: function () { return v1_11.diff; } });

@@ -517,26 +517,2 @@ import * as t from 'io-ts';

name: string;
imagePieces: {
[x: string]: {
[x: string]: {
$version: 1;
cellH: number;
cellW: number;
cellX: number;
cellY: number;
h: number;
isCellMode: boolean;
isPrivate: boolean;
w: number;
x: number;
y: number;
image: {
$version: 1;
path: string;
sourceType: "Default" | "FirebaseStorage";
} | null | undefined;
memo: string;
name: string;
} | undefined;
} | undefined;
} | null | undefined;
} | undefined;

@@ -710,2 +686,32 @@ } | undefined;

role: "Player" | "Spectator" | "Master" | null | undefined;
imagePieceValues: {
[x: string]: {
$version: 1;
image: {
$version: 1;
path: string;
sourceType: "Default" | "FirebaseStorage";
} | null | undefined;
isPrivate: boolean;
memo: string;
name: string;
pieces: {
[x: string]: {
[x: string]: {
$version: 1;
cellH: number;
cellW: number;
cellX: number;
cellY: number;
h: number;
isCellMode: boolean;
isPrivate: boolean;
w: number;
x: number;
y: number;
} | undefined;
} | undefined;
};
} | undefined;
} | null | undefined;
} | undefined;

@@ -712,0 +718,0 @@ };

import * as t from 'io-ts';
import * as ImagePiece from './imagePiece/v1';
import { filePath } from '../../filePath/v1';
import * as ReplaceOperation from '../../util/replaceOperation';
import * as DualKeyRecordOperation from '../../util/dualKeyRecordOperation';
import { Apply, ClientTransform, Compose, Diff, RequestedBy, Restore, ServerTransform } from '../../util/type';

@@ -22,22 +20,2 @@ export declare const state: t.TypeC<{

name: t.StringC;
imagePieces: t.UnionC<[t.RecordC<t.StringC, t.UnionC<[t.RecordC<t.StringC, t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
cellH: t.NumberC;
cellW: t.NumberC;
cellX: t.NumberC;
cellY: t.NumberC;
h: t.NumberC;
isCellMode: t.BooleanC;
isPrivate: t.BooleanC;
w: t.NumberC;
x: t.NumberC;
y: t.NumberC;
image: t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
path: t.StringC;
sourceType: t.UnionC<[t.LiteralC<"Default">, t.LiteralC<"FirebaseStorage">]>;
}>, t.NullC, t.UndefinedC]>;
memo: t.StringC;
name: t.StringC;
}>, t.UndefinedC]>>, t.UndefinedC]>>, t.NullC, t.UndefinedC]>;
}>;

@@ -79,83 +57,2 @@ export declare type State = t.TypeOf<typeof state>;

}>;
imagePieces: t.RecordC<t.StringC, t.UnionC<[t.RecordC<t.StringC, t.UnionC<[t.UnionC<[t.TypeC<{
type: t.LiteralC<"replace">;
replace: t.PartialC<{
oldValue: t.TypeC<{
$version: t.LiteralC<1>;
cellH: t.NumberC;
cellW: t.NumberC;
cellX: t.NumberC;
cellY: t.NumberC;
h: t.NumberC;
isCellMode: t.BooleanC;
isPrivate: t.BooleanC;
w: t.NumberC;
x: t.NumberC;
y: t.NumberC;
image: t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
path: t.StringC;
sourceType: t.UnionC<[t.LiteralC<"Default">, t.LiteralC<"FirebaseStorage">]>;
}>, t.NullC, t.UndefinedC]>;
memo: t.StringC;
name: t.StringC;
}>;
}>;
}>, t.TypeC<{
type: t.LiteralC<"update">;
update: t.IntersectionC<[t.TypeC<{
$version: t.LiteralC<1>;
}>, t.PartialC<{
cellH: t.TypeC<{
oldValue: t.NumberC;
}>;
cellW: t.TypeC<{
oldValue: t.NumberC;
}>;
cellX: t.TypeC<{
oldValue: t.NumberC;
}>;
cellY: t.TypeC<{
oldValue: t.NumberC;
}>;
h: t.TypeC<{
oldValue: t.NumberC;
}>;
isCellMode: t.TypeC<{
oldValue: t.BooleanC;
}>;
isPrivate: t.TypeC<{
oldValue: t.BooleanC;
}>;
w: t.TypeC<{
oldValue: t.NumberC;
}>;
x: t.TypeC<{
oldValue: t.NumberC;
}>;
y: t.TypeC<{
oldValue: t.NumberC;
}>;
image: t.TypeC<{
oldValue: t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
path: t.StringC;
sourceType: t.UnionC<[t.LiteralC<"Default">, t.LiteralC<"FirebaseStorage">]>;
}>, t.NullC, t.UndefinedC]>;
}>;
memo: t.ArrayC<t.UnionC<[t.TypeC<{
t: t.LiteralC<"r">;
r: t.NumberC;
}>, t.TypeC<{
t: t.LiteralC<"i">;
i: t.NumberC;
}>, t.TypeC<{
t: t.LiteralC<"d">;
d: t.StringC;
}>]>>;
name: t.TypeC<{
oldValue: t.StringC;
}>;
}>]>;
}>]>, t.UndefinedC]>>, t.UndefinedC]>>;
}>]>;

@@ -197,83 +94,2 @@ export declare type DownOperation = t.TypeOf<typeof downOperation>;

}>;
imagePieces: t.RecordC<t.StringC, t.UnionC<[t.RecordC<t.StringC, t.UnionC<[t.UnionC<[t.TypeC<{
type: t.LiteralC<"replace">;
replace: t.PartialC<{
newValue: t.TypeC<{
$version: t.LiteralC<1>;
cellH: t.NumberC;
cellW: t.NumberC;
cellX: t.NumberC;
cellY: t.NumberC;
h: t.NumberC;
isCellMode: t.BooleanC;
isPrivate: t.BooleanC;
w: t.NumberC;
x: t.NumberC;
y: t.NumberC;
image: t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
path: t.StringC;
sourceType: t.UnionC<[t.LiteralC<"Default">, t.LiteralC<"FirebaseStorage">]>;
}>, t.NullC, t.UndefinedC]>;
memo: t.StringC;
name: t.StringC;
}>;
}>;
}>, t.TypeC<{
type: t.LiteralC<"update">;
update: t.IntersectionC<[t.TypeC<{
$version: t.LiteralC<1>;
}>, t.PartialC<{
cellH: t.TypeC<{
newValue: t.NumberC;
}>;
cellW: t.TypeC<{
newValue: t.NumberC;
}>;
cellX: t.TypeC<{
newValue: t.NumberC;
}>;
cellY: t.TypeC<{
newValue: t.NumberC;
}>;
h: t.TypeC<{
newValue: t.NumberC;
}>;
isCellMode: t.TypeC<{
newValue: t.BooleanC;
}>;
isPrivate: t.TypeC<{
newValue: t.BooleanC;
}>;
w: t.TypeC<{
newValue: t.NumberC;
}>;
x: t.TypeC<{
newValue: t.NumberC;
}>;
y: t.TypeC<{
newValue: t.NumberC;
}>;
image: t.TypeC<{
newValue: t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
path: t.StringC;
sourceType: t.UnionC<[t.LiteralC<"Default">, t.LiteralC<"FirebaseStorage">]>;
}>, t.NullC, t.UndefinedC]>;
}>;
memo: t.ArrayC<t.UnionC<[t.TypeC<{
t: t.LiteralC<"r">;
r: t.NumberC;
}>, t.TypeC<{
t: t.LiteralC<"i">;
i: t.StringC;
}>, t.TypeC<{
t: t.LiteralC<"d">;
d: t.NumberC;
}>]>>;
name: t.TypeC<{
newValue: t.StringC;
}>;
}>]>;
}>]>, t.UndefinedC]>>, t.UndefinedC]>>;
}>]>;

@@ -292,5 +108,4 @@ export declare type UpOperation = t.TypeOf<typeof upOperation>;

name?: ReplaceOperation.ReplaceValueTwoWayOperation<string>;
imagePieces?: DualKeyRecordOperation.DualKeyRecordTwoWayOperation<ImagePiece.State, ImagePiece.TwoWayOperation>;
};
export declare const toClientState: (requestedBy: RequestedBy) => (source: State) => State;
export declare const toClientState: (source: State) => State;
export declare const toDownOperation: (source: TwoWayOperation) => DownOperation;

@@ -297,0 +112,0 @@ export declare const toUpOperation: (source: TwoWayOperation) => UpOperation;

@@ -24,7 +24,4 @@ "use strict";

const t = __importStar(require("io-ts"));
const ImagePiece = __importStar(require("./imagePiece/v1"));
const v1_1 = require("../../filePath/v1");
const ReplaceOperation = __importStar(require("../../util/replaceOperation"));
const DualKeyRecordOperation = __importStar(require("../../util/dualKeyRecordOperation"));
const type_1 = require("../../util/type");
const createOperation_1 = require("../../util/createOperation");

@@ -34,3 +31,2 @@ const record_1 = require("../../util/record");

const util_1 = require("@kizahasi/util");
const recordOperationElement_1 = require("../../util/recordOperationElement");
const stringDownOperation = t.type({ oldValue: t.string });

@@ -51,5 +47,2 @@ const stringUpOperation = t.type({ newValue: t.string });

name: t.string,
// NumberPieceやDicePieceとは異なり、keyは (作成者, ランダムなID)。
// TODO: 互換性のため、maybeにしている。互換性を壊していい変更をする場合、このmaybeを外す。
imagePieces: util_1.maybe(record_1.record(t.string, record_1.record(t.string, ImagePiece.state))),
});

@@ -66,3 +59,2 @@ exports.downOperation = createOperation_1.createOperation(1, {

name: stringDownOperation,
imagePieces: record_1.record(t.string, record_1.record(t.string, recordOperationElement_1.recordDownOperationElementFactory(ImagePiece.state, ImagePiece.downOperation))),
});

@@ -79,44 +71,16 @@ exports.upOperation = createOperation_1.createOperation(1, {

name: stringUpOperation,
imagePieces: record_1.record(t.string, record_1.record(t.string, recordOperationElement_1.recordUpOperationElementFactory(ImagePiece.state, ImagePiece.upOperation))),
});
const toClientState = (requestedBy) => (source) => {
var _a;
return {
...source,
imagePieces: DualKeyRecordOperation.toClientState({
serverState: (_a = source.imagePieces) !== null && _a !== void 0 ? _a : {},
isPrivate: (state, key) => type_1.RequestedBy.createdByMe({ requestedBy, userUid: key.first }) && state.isPrivate,
toClientState: ({ state }) => ImagePiece.toClientState(state),
}),
};
const toClientState = (source) => {
return source;
};
exports.toClientState = toClientState;
const toDownOperation = (source) => {
return {
...source,
imagePieces: source.imagePieces == null
? undefined
: util_1.chooseDualKeyRecord(source.imagePieces, operation => recordOperationElement_1.mapRecordOperationElement({
source: operation,
mapReplace: x => x,
mapOperation: ImagePiece.toDownOperation,
})),
};
return source;
};
exports.toDownOperation = toDownOperation;
const toUpOperation = (source) => {
return {
...source,
imagePieces: source.imagePieces == null
? undefined
: util_1.chooseDualKeyRecord(source.imagePieces, operation => recordOperationElement_1.mapRecordOperationElement({
source: operation,
mapReplace: x => x,
mapOperation: ImagePiece.toUpOperation,
})),
};
return source;
};
exports.toUpOperation = toUpOperation;
const apply = ({ state, operation }) => {
var _a;
const result = { ...state };

@@ -150,13 +114,2 @@ if (operation.backgroundImage != null) {

}
const imagePieces = DualKeyRecordOperation.apply({
prevState: (_a = state.imagePieces) !== null && _a !== void 0 ? _a : {},
operation: operation.imagePieces,
innerApply: ({ prevState, operation }) => {
return ImagePiece.apply({ state: prevState, operation });
},
});
if (imagePieces.isError) {
return imagePieces;
}
result.imagePieces = imagePieces.value;
return result_1.Result.ok(result);

@@ -166,3 +119,3 @@ };

const applyBack = ({ state, operation }) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
var _a, _b, _c, _d, _e, _f, _g, _h;
const result = {

@@ -198,13 +151,2 @@ ...state,

}
const imagePieces = DualKeyRecordOperation.applyBack({
nextState: (_j = state.imagePieces) !== null && _j !== void 0 ? _j : {},
operation: operation.imagePieces,
innerApplyBack: ({ state, operation }) => {
return ImagePiece.applyBack({ state, operation });
},
});
if (imagePieces.isError) {
return imagePieces;
}
result.imagePieces = imagePieces.value;
return result_1.Result.ok(result);

@@ -214,14 +156,4 @@ };

const composeDownOperation = ({ first, second }) => {
const imagePieces = DualKeyRecordOperation.composeDownOperation({
first: first.imagePieces,
second: second.imagePieces,
innerApplyBack: params => ImagePiece.applyBack(params),
innerCompose: params => ImagePiece.composeDownOperation(params),
});
if (imagePieces.isError) {
return imagePieces;
}
const valueProps = {
$version: 1,
imagePieces: imagePieces.value,
backgroundImage: ReplaceOperation.composeDownOperation(first.backgroundImage, second.backgroundImage),

@@ -241,28 +173,17 @@ backgroundImageZoom: ReplaceOperation.composeDownOperation(first.backgroundImageZoom, second.backgroundImageZoom),

const restore = ({ nextState, downOperation, }) => {
var _a, _b, _c, _d;
var _a, _b, _c;
if (downOperation === undefined) {
return result_1.Result.ok({ prevState: nextState, twoWayOperation: undefined });
}
const imagePieces = DualKeyRecordOperation.restore({
nextState: (_a = nextState.imagePieces) !== null && _a !== void 0 ? _a : {},
downOperation: downOperation.imagePieces,
innerDiff: params => ImagePiece.diff(params),
innerRestore: params => ImagePiece.restore(params),
});
if (imagePieces.isError) {
return imagePieces;
}
const prevState = {
...nextState,
imagePieces: imagePieces.value.prevState,
};
const twoWayOperation = {
$version: 1,
imagePieces: imagePieces.value.twoWayOperation,
};
if (downOperation.backgroundImage !== undefined) {
prevState.backgroundImage = (_b = downOperation.backgroundImage.oldValue) !== null && _b !== void 0 ? _b : undefined;
prevState.backgroundImage = (_a = downOperation.backgroundImage.oldValue) !== null && _a !== void 0 ? _a : undefined;
twoWayOperation.backgroundImage = {
oldValue: (_c = downOperation.backgroundImage.oldValue) !== null && _c !== void 0 ? _c : undefined,
newValue: (_d = nextState.backgroundImage) !== null && _d !== void 0 ? _d : undefined,
oldValue: (_b = downOperation.backgroundImage.oldValue) !== null && _b !== void 0 ? _b : undefined,
newValue: (_c = nextState.backgroundImage) !== null && _c !== void 0 ? _c : undefined,
};

@@ -330,9 +251,3 @@ }

const diff = ({ prevState, nextState }) => {
var _a, _b;
const imagePieces = DualKeyRecordOperation.diff({
prevState: (_a = prevState.imagePieces) !== null && _a !== void 0 ? _a : {},
nextState: (_b = nextState.imagePieces) !== null && _b !== void 0 ? _b : {},
innerDiff: params => ImagePiece.diff(params),
});
const resultType = { $version: 1, imagePieces };
const resultType = { $version: 1 };
if (prevState.backgroundImage !== nextState.backgroundImage) {

@@ -399,26 +314,3 @@ resultType.backgroundImage = {

const serverTransform = (requestedBy) => ({ prevState, currentState, clientOperation, serverOperation }) => {
var _a, _b;
const imagePieces = DualKeyRecordOperation.serverTransform({
first: serverOperation === null || serverOperation === void 0 ? void 0 : serverOperation.imagePieces,
second: clientOperation.imagePieces,
prevState: (_a = prevState.imagePieces) !== null && _a !== void 0 ? _a : {},
nextState: (_b = currentState.imagePieces) !== null && _b !== void 0 ? _b : {},
innerTransform: ({ first, second, prevState, nextState }) => ImagePiece.serverTransform({
prevState,
currentState: nextState,
serverOperation: first,
clientOperation: second,
}),
toServerState: state => state,
cancellationPolicy: {
cancelUpdate: ({ key, nextState }) => !type_1.RequestedBy.createdByMe({ requestedBy, userUid: key.first }) &&
nextState.isPrivate,
cancelRemove: ({ key, nextState }) => !type_1.RequestedBy.createdByMe({ requestedBy, userUid: key.first }) &&
nextState.isPrivate,
},
});
if (imagePieces.isError) {
return imagePieces;
}
const twoWayOperation = { $version: 1, imagePieces: imagePieces.value };
const twoWayOperation = { $version: 1 };
twoWayOperation.backgroundImage = ReplaceOperation.serverTransform({

@@ -476,17 +368,2 @@ first: serverOperation === null || serverOperation === void 0 ? void 0 : serverOperation.backgroundImage,

const clientTransform = ({ first, second }) => {
const imagePieces = DualKeyRecordOperation.clientTransform({
first: first.imagePieces,
second: second.imagePieces,
innerTransform: params => ImagePiece.clientTransform(params),
innerDiff: params => {
const diff = ImagePiece.diff(params);
if (diff == null) {
return diff;
}
return ImagePiece.toUpOperation(diff);
},
});
if (imagePieces.isError) {
return imagePieces;
}
const backgroundImage = ReplaceOperation.clientTransform({

@@ -538,3 +415,2 @@ first: first.backgroundImage,

cellWidth: cellWidth.firstPrime,
imagePieces: imagePieces.value.firstPrime,
name: name.firstPrime,

@@ -552,3 +428,2 @@ };

cellWidth: cellWidth.secondPrime,
imagePieces: imagePieces.value.secondPrime,
name: name.secondPrime,

@@ -555,0 +430,0 @@ };

import * as t from 'io-ts';
import { Apply, ClientTransform, Compose, Diff, RequestedBy, Restore, ServerTransform } from '../../util/type';
import * as ReplaceOperation from '../../util/replaceOperation';
import { Maybe } from '@kizahasi/util';
import { CompositeKey, Maybe } from '@kizahasi/util';
import * as ImagePieceValue from './imagePieceValue/v1';
import * as RecordOperation from '../../util/recordOperation';
export declare const Player = "Player";

@@ -14,2 +16,26 @@ export declare const Spectator = "Spectator";

role: t.UnionC<[t.UnionC<[t.LiteralC<"Player">, t.LiteralC<"Spectator">, t.LiteralC<"Master">]>, t.NullC, t.UndefinedC]>;
imagePieceValues: t.UnionC<[t.RecordC<t.StringC, t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
image: t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
path: t.StringC;
sourceType: t.UnionC<[t.LiteralC<"Default">, t.LiteralC<"FirebaseStorage">]>;
}>, t.NullC, t.UndefinedC]>;
isPrivate: t.BooleanC;
memo: t.StringC;
name: t.StringC;
pieces: t.RecordC<t.StringC, t.UnionC<[t.RecordC<t.StringC, t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
cellH: t.NumberC;
cellW: t.NumberC;
cellX: t.NumberC;
cellY: t.NumberC;
h: t.NumberC;
isCellMode: t.BooleanC;
isPrivate: t.BooleanC;
w: t.NumberC;
x: t.NumberC;
y: t.NumberC;
}>, t.UndefinedC]>>, t.UndefinedC]>>;
}>, t.UndefinedC]>>, t.NullC, t.UndefinedC]>;
}>;

@@ -26,2 +52,114 @@ export declare type State = t.TypeOf<typeof state>;

}>;
imagePieceValues: t.RecordC<t.StringC, t.UnionC<[t.UnionC<[t.TypeC<{
type: t.LiteralC<"replace">;
replace: t.PartialC<{
oldValue: t.TypeC<{
$version: t.LiteralC<1>;
image: t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
path: t.StringC;
sourceType: t.UnionC<[t.LiteralC<"Default">, t.LiteralC<"FirebaseStorage">]>;
}>, t.NullC, t.UndefinedC]>;
isPrivate: t.BooleanC;
memo: t.StringC;
name: t.StringC;
pieces: t.RecordC<t.StringC, t.UnionC<[t.RecordC<t.StringC, t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
cellH: t.NumberC;
cellW: t.NumberC;
cellX: t.NumberC;
cellY: t.NumberC;
h: t.NumberC;
isCellMode: t.BooleanC;
isPrivate: t.BooleanC;
w: t.NumberC;
x: t.NumberC;
y: t.NumberC;
}>, t.UndefinedC]>>, t.UndefinedC]>>;
}>;
}>;
}>, t.TypeC<{
type: t.LiteralC<"update">;
update: t.IntersectionC<[t.TypeC<{
$version: t.LiteralC<1>;
}>, t.PartialC<{
image: t.TypeC<{
oldValue: t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
path: t.StringC;
sourceType: t.UnionC<[t.LiteralC<"Default">, t.LiteralC<"FirebaseStorage">]>;
}>, t.NullC, t.UndefinedC]>;
}>;
isPrivate: t.TypeC<{
oldValue: t.BooleanC;
}>;
memo: t.ArrayC<t.UnionC<[t.TypeC<{
t: t.LiteralC<"r">;
r: t.NumberC;
}>, t.TypeC<{
t: t.LiteralC<"i">;
i: t.NumberC;
}>, t.TypeC<{
t: t.LiteralC<"d">;
d: t.StringC;
}>]>>;
name: t.TypeC<{
oldValue: t.StringC;
}>;
pieces: t.RecordC<t.StringC, t.UnionC<[t.RecordC<t.StringC, t.UnionC<[t.UnionC<[t.TypeC<{
type: t.LiteralC<"replace">;
replace: t.PartialC<{
oldValue: t.TypeC<{
$version: t.LiteralC<1>;
cellH: t.NumberC;
cellW: t.NumberC;
cellX: t.NumberC;
cellY: t.NumberC;
h: t.NumberC;
isCellMode: t.BooleanC;
isPrivate: t.BooleanC;
w: t.NumberC;
x: t.NumberC;
y: t.NumberC;
}>;
}>;
}>, t.TypeC<{
type: t.LiteralC<"update">;
update: t.IntersectionC<[t.TypeC<{
$version: t.LiteralC<1>;
}>, t.PartialC<{
cellH: t.TypeC<{
oldValue: t.NumberC;
}>;
cellW: t.TypeC<{
oldValue: t.NumberC;
}>;
cellX: t.TypeC<{
oldValue: t.NumberC;
}>;
cellY: t.TypeC<{
oldValue: t.NumberC;
}>;
h: t.TypeC<{
oldValue: t.NumberC;
}>;
isCellMode: t.TypeC<{
oldValue: t.BooleanC;
}>;
isPrivate: t.TypeC<{
oldValue: t.BooleanC;
}>;
w: t.TypeC<{
oldValue: t.NumberC;
}>;
x: t.TypeC<{
oldValue: t.NumberC;
}>;
y: t.TypeC<{
oldValue: t.NumberC;
}>;
}>]>;
}>]>, t.UndefinedC]>>, t.UndefinedC]>>;
}>]>;
}>]>, t.UndefinedC]>>;
}>]>;

@@ -38,2 +176,114 @@ export declare type DownOperation = t.TypeOf<typeof downOperation>;

}>;
imagePieceValues: t.RecordC<t.StringC, t.UnionC<[t.UnionC<[t.TypeC<{
type: t.LiteralC<"replace">;
replace: t.PartialC<{
newValue: t.TypeC<{
$version: t.LiteralC<1>;
image: t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
path: t.StringC;
sourceType: t.UnionC<[t.LiteralC<"Default">, t.LiteralC<"FirebaseStorage">]>;
}>, t.NullC, t.UndefinedC]>;
isPrivate: t.BooleanC;
memo: t.StringC;
name: t.StringC;
pieces: t.RecordC<t.StringC, t.UnionC<[t.RecordC<t.StringC, t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
cellH: t.NumberC;
cellW: t.NumberC;
cellX: t.NumberC;
cellY: t.NumberC;
h: t.NumberC;
isCellMode: t.BooleanC;
isPrivate: t.BooleanC;
w: t.NumberC;
x: t.NumberC;
y: t.NumberC;
}>, t.UndefinedC]>>, t.UndefinedC]>>;
}>;
}>;
}>, t.TypeC<{
type: t.LiteralC<"update">;
update: t.IntersectionC<[t.TypeC<{
$version: t.LiteralC<1>;
}>, t.PartialC<{
image: t.TypeC<{
newValue: t.UnionC<[t.TypeC<{
$version: t.LiteralC<1>;
path: t.StringC;
sourceType: t.UnionC<[t.LiteralC<"Default">, t.LiteralC<"FirebaseStorage">]>;
}>, t.NullC, t.UndefinedC]>;
}>;
isPrivate: t.TypeC<{
newValue: t.BooleanC;
}>;
memo: t.ArrayC<t.UnionC<[t.TypeC<{
t: t.LiteralC<"r">;
r: t.NumberC;
}>, t.TypeC<{
t: t.LiteralC<"i">;
i: t.StringC;
}>, t.TypeC<{
t: t.LiteralC<"d">;
d: t.NumberC;
}>]>>;
name: t.TypeC<{
newValue: t.StringC;
}>;
pieces: t.RecordC<t.StringC, t.UnionC<[t.RecordC<t.StringC, t.UnionC<[t.UnionC<[t.TypeC<{
type: t.LiteralC<"replace">;
replace: t.PartialC<{
newValue: t.TypeC<{
$version: t.LiteralC<1>;
cellH: t.NumberC;
cellW: t.NumberC;
cellX: t.NumberC;
cellY: t.NumberC;
h: t.NumberC;
isCellMode: t.BooleanC;
isPrivate: t.BooleanC;
w: t.NumberC;
x: t.NumberC;
y: t.NumberC;
}>;
}>;
}>, t.TypeC<{
type: t.LiteralC<"update">;
update: t.IntersectionC<[t.TypeC<{
$version: t.LiteralC<1>;
}>, t.PartialC<{
cellH: t.TypeC<{
newValue: t.NumberC;
}>;
cellW: t.TypeC<{
newValue: t.NumberC;
}>;
cellX: t.TypeC<{
newValue: t.NumberC;
}>;
cellY: t.TypeC<{
newValue: t.NumberC;
}>;
h: t.TypeC<{
newValue: t.NumberC;
}>;
isCellMode: t.TypeC<{
newValue: t.BooleanC;
}>;
isPrivate: t.TypeC<{
newValue: t.BooleanC;
}>;
w: t.TypeC<{
newValue: t.NumberC;
}>;
x: t.TypeC<{
newValue: t.NumberC;
}>;
y: t.TypeC<{
newValue: t.NumberC;
}>;
}>]>;
}>]>, t.UndefinedC]>>, t.UndefinedC]>>;
}>]>;
}>]>, t.UndefinedC]>>;
}>]>;

@@ -45,4 +295,5 @@ export declare type UpOperation = t.TypeOf<typeof upOperation>;

role?: ReplaceOperation.ReplaceValueTwoWayOperation<Maybe<ParticipantRole>>;
imagePieceValues?: RecordOperation.RecordTwoWayOperation<ImagePieceValue.State, ImagePieceValue.TwoWayOperation>;
};
export declare const toClientState: (source: State) => State;
export declare const toClientState: (requestedBy: RequestedBy, participantKey: string, activeBoardKey: CompositeKey | null) => (source: State) => State;
export declare const toDownOperation: (source: TwoWayOperation) => DownOperation;

@@ -49,0 +300,0 @@ export declare const toUpOperation: (source: TwoWayOperation) => UpOperation;

@@ -30,2 +30,5 @@ "use strict";

const util_1 = require("@kizahasi/util");
const ImagePieceValue = __importStar(require("./imagePieceValue/v1"));
const recordOperationElement_1 = require("../../util/recordOperationElement");
const RecordOperation = __importStar(require("../../util/recordOperation"));
exports.Player = 'Player';

@@ -39,2 +42,4 @@ exports.Spectator = 'Spectator';

role: util_1.maybe(participantRole),
// TODO: 互換性のため、maybeを付けている。互換性を壊しても良くなったときはmaybeを外す。
imagePieceValues: util_1.maybe(record_1.record(t.string, ImagePieceValue.state)),
});

@@ -44,2 +49,3 @@ exports.downOperation = createOperation_1.createOperation(1, {

role: t.type({ oldValue: util_1.maybe(participantRole) }),
imagePieceValues: record_1.record(t.string, recordOperationElement_1.recordDownOperationElementFactory(ImagePieceValue.state, ImagePieceValue.downOperation)),
});

@@ -49,16 +55,45 @@ exports.upOperation = createOperation_1.createOperation(1, {

role: t.type({ newValue: util_1.maybe(participantRole) }),
imagePieceValues: record_1.record(t.string, recordOperationElement_1.recordUpOperationElementFactory(ImagePieceValue.state, ImagePieceValue.upOperation)),
});
const toClientState = (source) => {
return source;
const toClientState = (requestedBy, participantKey, activeBoardKey) => (source) => {
var _a;
const createdByMe = type_1.RequestedBy.createdByMe({ requestedBy, userUid: participantKey });
return {
...source,
imagePieceValues: RecordOperation.toClientState({
serverState: (_a = source.imagePieceValues) !== null && _a !== void 0 ? _a : {},
isPrivate: state => state.isPrivate && !createdByMe,
toClientState: ({ state }) => ImagePieceValue.toClientState(requestedBy, activeBoardKey)(state),
}),
};
};
exports.toClientState = toClientState;
const toDownOperation = (source) => {
return source;
return {
...source,
imagePieceValues: source.imagePieceValues == null
? undefined
: util_1.chooseRecord(source.imagePieceValues, operation => recordOperationElement_1.mapRecordOperationElement({
source: operation,
mapReplace: x => x,
mapOperation: ImagePieceValue.toDownOperation,
})),
};
};
exports.toDownOperation = toDownOperation;
const toUpOperation = (source) => {
return source;
return {
...source,
imagePieceValues: source.imagePieceValues == null
? undefined
: util_1.chooseRecord(source.imagePieceValues, operation => recordOperationElement_1.mapRecordOperationElement({
source: operation,
mapReplace: x => x,
mapOperation: ImagePieceValue.toUpOperation,
})),
};
};
exports.toUpOperation = toUpOperation;
const apply = ({ state, operation }) => {
var _a, _b;
const result = { ...state };

@@ -71,2 +106,16 @@ if (operation.name != null) {

}
const imagePieceValues = RecordOperation.apply({
prevState: (_a = state.imagePieceValues) !== null && _a !== void 0 ? _a : {},
operation: (_b = operation.imagePieceValues) !== null && _b !== void 0 ? _b : {},
innerApply: ({ prevState, operation: upOperation }) => {
return ImagePieceValue.apply({
state: prevState,
operation: upOperation,
});
},
});
if (imagePieceValues.isError) {
return imagePieceValues;
}
result.imagePieceValues = imagePieceValues.value;
return result_1.Result.ok(result);

@@ -76,2 +125,3 @@ };

const applyBack = ({ state, operation }) => {
var _a, _b;
const result = { ...state };

@@ -84,2 +134,16 @@ if (operation.name != null) {

}
const imagePieceValues = RecordOperation.applyBack({
nextState: (_a = state.imagePieceValues) !== null && _a !== void 0 ? _a : {},
operation: (_b = operation.imagePieceValues) !== null && _b !== void 0 ? _b : {},
innerApplyBack: ({ state, operation }) => {
return ImagePieceValue.applyBack({
state,
operation,
});
},
});
if (imagePieceValues.isError) {
return imagePieceValues;
}
result.imagePieceValues = imagePieceValues.value;
return result_1.Result.ok(result);

@@ -90,2 +154,11 @@ };

var _a, _b, _c, _d;
const imagePieceValues = RecordOperation.composeDownOperation({
first: first.imagePieceValues,
second: second.imagePieceValues,
innerApplyBack: params => ImagePieceValue.applyBack(params),
innerCompose: params => ImagePieceValue.composeDownOperation(params),
});
if (imagePieceValues.isError) {
return imagePieceValues;
}
const valueProps = {

@@ -95,2 +168,3 @@ $version: 1,

role: ReplaceOperation.composeDownOperation((_c = first.role) !== null && _c !== void 0 ? _c : undefined, (_d = second.role) !== null && _d !== void 0 ? _d : undefined),
imagePieceValues: imagePieceValues.value,
};

@@ -101,11 +175,22 @@ return result_1.Result.ok(valueProps);

const restore = ({ nextState, downOperation, }) => {
var _a, _b;
var _a, _b, _c;
if (downOperation === undefined) {
return result_1.Result.ok({ prevState: nextState, twoWayOperation: undefined });
}
const imagePieceValues = RecordOperation.restore({
nextState: (_a = nextState.imagePieceValues) !== null && _a !== void 0 ? _a : {},
downOperation: downOperation.imagePieceValues,
innerDiff: params => ImagePieceValue.diff(params),
innerRestore: params => ImagePieceValue.restore(params),
});
if (imagePieceValues.isError) {
return imagePieceValues;
}
const prevState = {
...nextState,
imagePieceValues: imagePieceValues.value.prevState,
};
const twoWayOperation = {
$version: 1,
imagePieceValues: imagePieceValues.value.twoWayOperation,
};

@@ -120,5 +205,5 @@ if (downOperation.name != null) {

if (downOperation.role != null) {
prevState.role = (_a = downOperation.role.oldValue) !== null && _a !== void 0 ? _a : undefined;
prevState.role = (_b = downOperation.role.oldValue) !== null && _b !== void 0 ? _b : undefined;
twoWayOperation.role = {
oldValue: (_b = downOperation.role.oldValue) !== null && _b !== void 0 ? _b : undefined,
oldValue: (_c = downOperation.role.oldValue) !== null && _c !== void 0 ? _c : undefined,
newValue: nextState.role,

@@ -131,4 +216,11 @@ };

const diff = ({ prevState, nextState }) => {
var _a, _b;
const imagePieceValues = RecordOperation.diff({
prevState: (_a = prevState.imagePieceValues) !== null && _a !== void 0 ? _a : {},
nextState: (_b = nextState.imagePieceValues) !== null && _b !== void 0 ? _b : {},
innerDiff: params => ImagePieceValue.diff(params),
});
const result = {
$version: 1,
imagePieceValues,
};

@@ -148,10 +240,33 @@ if (prevState.name !== nextState.name) {

const serverTransform = ({ requestedBy, participantKey, activeBoardSecondKey, }) => ({ prevState, currentState, clientOperation, serverOperation }) => {
var _a, _b, _c, _d;
var _a, _b, _c, _d, _e, _f;
const createdByMe = type_1.RequestedBy.createdByMe({ requestedBy, userUid: participantKey });
const imagePieceValues = RecordOperation.serverTransform({
first: serverOperation === null || serverOperation === void 0 ? void 0 : serverOperation.imagePieceValues,
second: clientOperation.imagePieceValues,
prevState: (_a = prevState.imagePieceValues) !== null && _a !== void 0 ? _a : {},
nextState: (_b = currentState.imagePieceValues) !== null && _b !== void 0 ? _b : {},
innerTransform: ({ first, second, prevState, nextState }) => ImagePieceValue.serverTransform(createdByMe)({
prevState,
currentState: nextState,
serverOperation: first,
clientOperation: second,
}),
toServerState: state => state,
cancellationPolicy: {
cancelCreate: () => !createdByMe,
cancelUpdate: state => !createdByMe && state.nextState.isPrivate,
cancelRemove: state => !createdByMe && state.nextState.isPrivate,
},
});
if (imagePieceValues.isError) {
return imagePieceValues;
}
const twoWayOperation = {
$version: 1,
imagePieceValues: imagePieceValues.value,
};
if (type_1.RequestedBy.createdByMe({ requestedBy, userUid: participantKey })) {
if (createdByMe) {
twoWayOperation.name = ReplaceOperation.serverTransform({
first: (_a = serverOperation === null || serverOperation === void 0 ? void 0 : serverOperation.name) !== null && _a !== void 0 ? _a : undefined,
second: (_b = clientOperation.name) !== null && _b !== void 0 ? _b : undefined,
first: (_c = serverOperation === null || serverOperation === void 0 ? void 0 : serverOperation.name) !== null && _c !== void 0 ? _c : undefined,
second: (_d = clientOperation.name) !== null && _d !== void 0 ? _d : undefined,
prevState: prevState.name,

@@ -162,4 +277,4 @@ });

twoWayOperation.role = ReplaceOperation.serverTransform({
first: (_c = serverOperation === null || serverOperation === void 0 ? void 0 : serverOperation.role) !== null && _c !== void 0 ? _c : undefined,
second: (_d = clientOperation.role) !== null && _d !== void 0 ? _d : undefined,
first: (_e = serverOperation === null || serverOperation === void 0 ? void 0 : serverOperation.role) !== null && _e !== void 0 ? _e : undefined,
second: (_f = clientOperation.role) !== null && _f !== void 0 ? _f : undefined,
prevState: prevState.role,

@@ -175,2 +290,17 @@ });

const clientTransform = ({ first, second }) => {
const imagePieceValues = RecordOperation.clientTransform({
first: first.imagePieceValues,
second: second.imagePieceValues,
innerTransform: params => ImagePieceValue.clientTransform(params),
innerDiff: params => {
const diff = ImagePieceValue.diff(params);
if (diff == null) {
return diff;
}
return ImagePieceValue.toUpOperation(diff);
},
});
if (imagePieceValues.isError) {
return imagePieceValues;
}
const name = ReplaceOperation.clientTransform({

@@ -186,2 +316,3 @@ first: first.name,

$version: 1,
imagePieceValues: imagePieceValues.value.firstPrime,
name: name.firstPrime,

@@ -192,2 +323,3 @@ role: role.firstPrime,

$version: 1,
imagePieceValues: imagePieceValues.value.secondPrime,
name: name.secondPrime,

@@ -194,0 +326,0 @@ role: role.secondPrime,

@@ -130,3 +130,3 @@ "use strict";

},
toClientState: ({ state }) => Board.toClientState(requestedBy)(state),
toClientState: ({ state }) => Board.toClientState(state),
});

@@ -173,3 +173,6 @@ };

isPrivate: () => false,
toClientState: ({ state }) => Participant.toClientState(state),
toClientState: ({ state, key }) => {
var _a;
return Participant.toClientState(requestedBy, key, (_a = source.activeBoardKey) !== null && _a !== void 0 ? _a : null)(state);
},
}),

@@ -176,0 +179,0 @@ strParamNames: RecordOperation.toClientState({

{
"version": "0.9.2",
"version": "0.10.0",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc