Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbf7a271d7 | ||
|
|
597232ae0b |
No files matched your search
@@ -4,7 +4,7 @@
|
|||||||
"$className": "DataModel",
|
"$className": "DataModel",
|
||||||
|
|
||||||
"ServerScriptService": {
|
"ServerScriptService": {
|
||||||
"MarcSync-feature/SetupManager": {
|
"MarcSync-feature/SubscriptionManager": {
|
||||||
"$path": "src/MarcSync"
|
"$path": "src/MarcSync"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,16 +56,16 @@ end
|
|||||||
local marcsync = {}
|
local marcsync = {}
|
||||||
marcsync.__index = marcsync
|
marcsync.__index = marcsync
|
||||||
marcsync.request = {}
|
marcsync.request = {}
|
||||||
function marcsync.new(token: string)
|
function marcsync.new(token: string):typeof(marcsync)
|
||||||
if not token then warn("Token not provided while creating a new MarcSync Object.") end
|
if not token then warn("Token not provided while creating a new MarcSync Object.") end
|
||||||
if not tokens[token] then warn("Token provided for creating a new MarcSync Object not Found in Token Table, using it as token instead.") else token = tokens[token] end
|
if not tokens[token] then warn("Token provided for creating a new MarcSync Object not Found in Token Table, using it as token instead.") else token = tokens[token] end
|
||||||
local self = setmetatable({}, marcsync)
|
local self = setmetatable({}, marcsync)
|
||||||
self._token = token
|
self._token = token
|
||||||
self.request._parent = self
|
self.request._parent = self
|
||||||
self.request.version._parent = self.request
|
self.request.version._parent = self.request
|
||||||
self.request.database._parent = self.request
|
|
||||||
self.request.collection._parent = self.request
|
self.request.collection._parent = self.request
|
||||||
self.utils._parent = self
|
self.utils._parent = self
|
||||||
|
self.events = require(script.Parent.Objects.SubscriptionManager)._new(token)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -160,25 +160,7 @@ function marcsync.request.collection:get(collectionName: string):typeof(require(
|
|||||||
if not collectionName then error("No CollectionName Provided") end
|
if not collectionName then error("No CollectionName Provided") end
|
||||||
return require(script.Parent.Objects.Collection)._new(collectionName, self._parent._parent._token)
|
return require(script.Parent.Objects.Collection)._new(collectionName, self._parent._parent._token)
|
||||||
end
|
end
|
||||||
marcsync.request.database = {}
|
marcsync.events = require(script.Parent.Objects.SubscriptionManager)
|
||||||
function marcsync.request.database:fetch(databaseId: number):DefaultResult
|
|
||||||
if typeof(self) ~= "table" then error("Please use : instead of .") end
|
|
||||||
if not self._parent then error("[MarcSync] Please set a Token before using MarcSync.") end
|
|
||||||
self._parent._parent:_checkInstallation()
|
|
||||||
if not databaseId then error("No DatabaseId Provided") end
|
|
||||||
local result;
|
|
||||||
local success, Error = pcall(function() result = HttpService:RequestAsync({Url = "https://api.marcthedev.it/marcsync/v0/database/"..databaseId, Headers = {["Authorization"]=self._parent._parent._token}}) end)
|
|
||||||
return self._parent._parent:_requestHandler(result, Error)
|
|
||||||
end
|
|
||||||
function marcsync.request.database:delete(databaseId: number):DefaultResult
|
|
||||||
if typeof(self) ~= "table" then error("Please use : instead of .") end
|
|
||||||
if not self._parent then error("[MarcSync] Please set a Token before using MarcSync.") end
|
|
||||||
self._parent._parent:_checkInstallation()
|
|
||||||
if not databaseId then error("No DatabaseId Provided") end
|
|
||||||
local result;
|
|
||||||
local success, Error = pcall(function() result = HttpService:RequestAsync({Url = "https://api.marcthedev.it/marcsync/v0/database/"..databaseId, Headers = {["Authorization"]=self._parent._parent._token}}) end)
|
|
||||||
return self._parent._parent:_requestHandler(result, Error)
|
|
||||||
end
|
|
||||||
marcsync.utils = {}
|
marcsync.utils = {}
|
||||||
function marcsync.utils.safeRequest(method: Function, arguments: {})
|
function marcsync.utils.safeRequest(method: Function, arguments: {})
|
||||||
--_checkInstallation()
|
--_checkInstallation()
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
|
|
||||||
-- VARIABLES
|
|
||||||
local MarcSync = script.Parent.Parent
|
|
||||||
|
|
||||||
local SetupManager = {}
|
|
||||||
|
|
||||||
function SetupManager.checkInstallation()
|
|
||||||
if not MarcSync:FindFirstChild("Plugins") or not MarcSync:FindFirstChild("Plugins"):IsA("Folder") then return end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function SetupManager._new()
|
|
||||||
local self = setmetatable({}, SetupManager)
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
return SetupManager
|
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
local MessagingService = game:GetService("MessagingService")
|
||||||
|
local HttpService = game:GetService("HttpService")
|
||||||
|
|
||||||
|
type CollectionCreatedResponse = {
|
||||||
|
DatabaseId: string,
|
||||||
|
CollectionName: string,
|
||||||
|
Collection: typeof(require(script.Parent.Collection))
|
||||||
|
}
|
||||||
|
|
||||||
|
type CollectionUpdatedResponse = {
|
||||||
|
DatabaseId: string,
|
||||||
|
oldCollectionName: string,
|
||||||
|
newCollectionName: string,
|
||||||
|
Collection: typeof(require(script.Parent.Collection))
|
||||||
|
}
|
||||||
|
|
||||||
|
type CollectionDeletedResponse = {
|
||||||
|
DatabaseId: string,
|
||||||
|
CollectionName: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type DocumentCreatedResponse = {
|
||||||
|
DatabaseId: string,
|
||||||
|
CollectionName: string,
|
||||||
|
DocumentId: string,
|
||||||
|
Entry: typeof(require(script.Parent.Entry))
|
||||||
|
}
|
||||||
|
type DocumentUpdatedResponse = {
|
||||||
|
DatabaseId: string,
|
||||||
|
CollectionName: string,
|
||||||
|
DocumentId: string,
|
||||||
|
oldEntry: typeof(require(script.Parent.Entry)),
|
||||||
|
newEntry: typeof(require(script.Parent.Entry))
|
||||||
|
}
|
||||||
|
|
||||||
|
type DocumentDeletedResponse = {
|
||||||
|
DatabaseId: string,
|
||||||
|
CollectionName: string,
|
||||||
|
DocumentId: string,
|
||||||
|
Entry: typeof(require(script.Parent.Entry))
|
||||||
|
}
|
||||||
|
|
||||||
|
local subscriptionManager = {}
|
||||||
|
subscriptionManager.__index = subscriptionManager
|
||||||
|
|
||||||
|
function subscriptionManager:onCollectionCreated(callback: (CollectionCreatedResponse) -> ()):RBXScriptConnection
|
||||||
|
if typeof(self) ~= "table" then error("Please use : instead of .") end
|
||||||
|
if not self._token then error("[MarcSync: SubscriptionManager] Invalid Object created or trying to access an destroied object.") end
|
||||||
|
local connection = MessagingService:SubscribeAsync("00MarcsyncCollectionCreated", function(message)
|
||||||
|
local messageTable = HttpService:JSONDecode(message.Data)
|
||||||
|
callback({
|
||||||
|
DatabaseId = messageTable[1],
|
||||||
|
CollectionName = messageTable[2].CollectionName,
|
||||||
|
Collection = require(script.Parent.Collection)._new(messageTable[2].CollectionName, self._token)
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
return self._createRBXScriptConnection(connection)
|
||||||
|
end
|
||||||
|
|
||||||
|
function subscriptionManager:onCollectionDeleted(callback: (CollectionDeletedResponse) -> ()):RBXScriptConnection
|
||||||
|
if typeof(self) ~= "table" then error("Please use : instead of .") end
|
||||||
|
if not self._token then error("[MarcSync: SubscriptionManager] Invalid Object created or trying to access an destroied object.") end
|
||||||
|
local connection = MessagingService:SubscribeAsync("00MarcsyncCollectionDeleted", function(message)
|
||||||
|
local messageTable = HttpService:JSONDecode(message.Data)
|
||||||
|
callback({
|
||||||
|
DatabaseId = messageTable[1],
|
||||||
|
CollectionName = messageTable[2].CollectionName
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
return self._createRBXScriptConnection(connection)
|
||||||
|
end
|
||||||
|
|
||||||
|
function subscriptionManager:onCollectionUpdated(callback: (CollectionUpdatedResponse) -> ()):RBXScriptConnection
|
||||||
|
if typeof(self) ~= "table" then error("Please use : instead of .") end
|
||||||
|
if not self._token then error("[MarcSync: SubscriptionManager] Invalid Object created or trying to access an destroied object.") end
|
||||||
|
local connection = MessagingService:SubscribeAsync("00MarcsyncCollectionUpdated", function(message)
|
||||||
|
local messageTable = HttpService:JSONDecode(message.Data)
|
||||||
|
callback({
|
||||||
|
DatabaseId = messageTable[1],
|
||||||
|
oldCollectionName = messageTable[2].oldCollectionName,
|
||||||
|
newCollectionName = messageTable[2].newCollectionName,
|
||||||
|
Collection = require(script.Parent.Collection)._new(messageTable[2].newCollectionName, self._token)
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
return self._createRBXScriptConnection(connection)
|
||||||
|
end
|
||||||
|
|
||||||
|
function subscriptionManager:onDocumentCreated(callback: (DocumentCreatedResponse) -> ()):RBXScriptConnection
|
||||||
|
if typeof(self) ~= "table" then error("Please use : instead of .") end
|
||||||
|
if not self._token then error("[MarcSync: SubscriptionManager] Invalid Object created or trying to access an destroied object.") end
|
||||||
|
local connection = MessagingService:SubscribeAsync("00MarcsyncDocumentCreated", function(message)
|
||||||
|
local messageTable = HttpService:JSONDecode(message.Data)
|
||||||
|
messageTable[2].DocumentValues = HttpService:JSONDecode(messageTable[2].DocumentValues)
|
||||||
|
messageTable[2].DocumentValues._id = messageTable[2].DocumentId
|
||||||
|
callback({
|
||||||
|
DatabaseId = messageTable[1],
|
||||||
|
CollectionName = messageTable[2].CollectionName,
|
||||||
|
DocumentId = messageTable[2].DocumentId,
|
||||||
|
Entry = require(script.Parent.Entry)._new(messageTable[2].CollectionName, messageTable[2].DocumentValues, self._token)
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
return self._createRBXScriptConnection(connection)
|
||||||
|
end
|
||||||
|
|
||||||
|
function subscriptionManager:onDocumentUpdated(callback: (DocumentUpdatedResponse) -> ()):RBXScriptConnection
|
||||||
|
if typeof(self) ~= "table" then error("Please use : instead of .") end
|
||||||
|
if not self._token then error("[MarcSync: SubscriptionManager] Invalid Object created or trying to access an destroied object.") end
|
||||||
|
local connection = MessagingService:SubscribeAsync("00MarcsyncDocumentUpdated", function(message)
|
||||||
|
local messageTable = HttpService:JSONDecode(message.Data)
|
||||||
|
messageTable[2].oldDocumentValues = HttpService:JSONDecode(messageTable[2].oldDocumentValues)
|
||||||
|
messageTable[2].oldDocumentValues._id = messageTable[2].DocumentId
|
||||||
|
messageTable[2].newDocumentValues = HttpService:JSONDecode(messageTable[2].newDocumentValues)
|
||||||
|
messageTable[2].newDocumentValues._id = messageTable[2].DocumentId
|
||||||
|
callback({
|
||||||
|
DatabaseId = messageTable[1],
|
||||||
|
CollectionName = messageTable[2].CollectionName,
|
||||||
|
DocumentId = messageTable[2].DocumentId,
|
||||||
|
oldEntry = require(script.Parent.Entry)._new(messageTable[2].CollectionName, messageTable[2].oldDocumentValues, self._token),
|
||||||
|
newEntry = require(script.Parent.Entry)._new(messageTable[2].CollectionName, messageTable[2].newDocumentValues, self._token)
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
return self._createRBXScriptConnection(connection)
|
||||||
|
end
|
||||||
|
|
||||||
|
function subscriptionManager:onDocumentDeleted(callback: (DocumentDeletedResponse) -> ()):RBXScriptConnection
|
||||||
|
if typeof(self) ~= "table" then error("Please use : instead of .") end
|
||||||
|
if not self._token then error("[MarcSync: SubscriptionManager] Invalid Object created or trying to access an destroied object.") end
|
||||||
|
local connection = MessagingService:SubscribeAsync("00MarcsyncDocumentDeleted", function(message)
|
||||||
|
local messageTable = HttpService:JSONDecode(message.Data)
|
||||||
|
messageTable[2].DocumentValues = HttpService:JSONDecode(messageTable[2].DocumentValues)
|
||||||
|
messageTable[2].DocumentValues._id = messageTable[2].DocumentId
|
||||||
|
callback({
|
||||||
|
DatabaseId = messageTable[1],
|
||||||
|
CollectionName = messageTable[2].CollectionName,
|
||||||
|
DocumentId = messageTable[2].DocumentId,
|
||||||
|
Entry = require(script.Parent.Entry)._new(messageTable[2].CollectionName, messageTable[2].DocumentValues, self._token)
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
return self._createRBXScriptConnection(connection)
|
||||||
|
end
|
||||||
|
|
||||||
|
function subscriptionManager._createRBXScriptConnection(subscription: RBXScriptConnection):RBXScriptConnection
|
||||||
|
local connection = {}
|
||||||
|
connection.Connected = true
|
||||||
|
connection.Disconnect = function()
|
||||||
|
subscription:Disconnect()
|
||||||
|
connection.Connected = false
|
||||||
|
end
|
||||||
|
return connection
|
||||||
|
end
|
||||||
|
|
||||||
|
function subscriptionManager._new(_token: string)
|
||||||
|
local self = setmetatable({}, subscriptionManager)
|
||||||
|
self._token = _token
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
return subscriptionManager
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
local MarcSync = script.Parent.Parent.Parent
|
|
||||||
type MarcSyncClient = typeof(require(MarcSync.Types.MARCSYNC_CLIENT))
|
|
||||||
|
|
||||||
local TestPlugin = {}
|
|
||||||
|
|
||||||
TestPlugin.Config = {
|
|
||||||
Name = "TestPlugin",
|
|
||||||
Description = "A Test Plugin",
|
|
||||||
Author = "Marc",
|
|
||||||
Version = "0.0.1",
|
|
||||||
Support = {
|
|
||||||
URL = "https://marcsync.dev",
|
|
||||||
Email = "test@example.com"
|
|
||||||
},
|
|
||||||
Setup = {
|
|
||||||
MarcSyncVersions = { "0.5.0" },
|
|
||||||
SetupAPIVersion = "v1",
|
|
||||||
Variables = {
|
|
||||||
TestVariable = {
|
|
||||||
Type = "string",
|
|
||||||
Required = true,
|
|
||||||
Default = "Hello World!",
|
|
||||||
Description = "A Test Variable"
|
|
||||||
},
|
|
||||||
TestVariable2 = {
|
|
||||||
Type = "number",
|
|
||||||
Required = false,
|
|
||||||
Description = "A Test Variable"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function TestPlugin.init(client: MarcSyncClient)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
return TestPlugin
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
return require(script.Parent.Parent["MarcSyncv0.5"])
|
|
||||||
Reference in new issue
Block a user